NO

Author Topic: Read String from Registry failed with exception fault  (Read 1578 times)

ml1969

  • Guest
Read String from Registry failed with exception fault
« on: August 16, 2009, 12:45:43 pm »
HI,


I wrote some Data in the registry of my PNA  (WinCe 5 .net)
it a string using REG_SZ for writing.

It works, I can see the values in the registry using a remote registry editor...


BUT, if I read these data the prgramms exits with an error.

My Code is..
Code: [Select]
...
DWORD dwDSize = 1;
DWORD dwValType = REG_DWORD;
HKEY hKey;
unsigned char *pbData;
wchar_t hstr[100];

rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\MySoft", 0, KEY_QUERY_VALUE, &hKey);
rc = RegQueryValueEx (hKey,  TEXT ("CLass"), NULL, &dwValType,   NULL, &dwDSize);

pbData = (PBYTE)LocalAlloc(LPTR,dwDSize);


rc = RegQueryValueEx (hKey, TEXT ("CLass"), NULL, &dwValType, pbData, &dwDSize);

swprintf(hstr, L"%s", *(int*)pbData);

RegCloseKey( hKey );
MessageBox(NULL, hstr, L"", MB_TOPMOST);

if I change swprintf(hstr, L"%s", *(int*)pbData);  to  swprintf(hstr, L"%c", *(int*)pbData); I get no error but only one character (its correct)

Where did I the misstake?


Michael