|
-
April 9th, 2010, 07:17 PM
#1
reading REG_SZ has extra spaces...
I have a method where I am reading a REG_SZ from a registry key. I know that the value of buff is exactly what is in the REG_SZ key, however when converting it to a System::String it gets extra spaces added in between the correct values.
Code:
String^ flags;
char buff[255];
dwType = REG_SZ;
dwSize = sizeof(buff);
memset(buff, 0, sizeof(buff));
if (::RegQueryValueEx( keyHandle, L"regvalue", NULL, &dwType,
(BYTE*) buff, &dwSize) == ERROR_SUCCESS){
char * temp = &buff[0];
flags = gcnew String(temp, 0, sizeof(buff));
//simple test to ensure what we are seeing
for (int i=0; i < sizeof (buff); i++ ){
printf(&buff[i]);
}
Console::WriteLine("\nCurrent REG_SZ value is: \n\t " + flags);
}
Sample output from the printf:
BOB, BOB
Sample output from the WriteLine:
B O B , B O B
Can anyone explain why and advise me how to correct it so that it does not add the spaces?
-
April 11th, 2010, 02:41 AM
#2
Re: reading REG_SZ has extra spaces...
Try to be more specific creating managed string:
flags = Marshal:: PtrToStringAnsi(IntPtr(temp));
Generally, don't mix managed and unmanaged types when it is not absolutely necessary. Use Microsoft:: Win32:: RegistryKey class for managed Registry operations.
-
April 11th, 2010, 05:06 AM
#3
Re: reading REG_SZ has extra spaces...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|