NO

Author Topic: Problem with RegQueryValueEx()  (Read 3574 times)

pitter2206

  • Guest
Problem with RegQueryValueEx()
« on: April 15, 2010, 05:27:27 PM »
Hi guys,

I´ve got a problem with reading in the registry...

I want to look if the string of the following BTStatus is "1" or "0":
Code: [Select]
[HKEY_LOCAL_MACHINE\GoPal]
"BTStatus"="1"
If the BTStatus = 0  I want to do nothing...

So... my problem is, that I can´t test it here, because I am fixing a problem of a friend of mine...

I´ve got this code to read the string of a entry:
Code: [Select]
#include <windows.h>
#include <windowsx.h>

HKEY hkey;


int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdLine, int nCmdShow)
{
CreateProcess(L"\\My Flash Disk\\Navigation\\mnavdce.exe\0",NULL,0,0,FALSE,0, 0, 0, NULL, NULL);
Sleep(5000);

DWORD dwData = 256;
BYTE cDaten[256] = "";
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"GoPal", 0, KEY_READ, &hkey)== ERROR_SUCCESS);
{
RegQueryValueEx(hkey, L"BTStatus",0,0,cDaten,&dwData);
if (cDaten == "1");
{
CreateProcess(L"\\My Flash Disk\\Bluetooth\\PhoneLink.exe\0",NULL,0,0,FALSE,0, 0, 0, NULL, NULL);
}
}
RegCloseKey(hkey);
return 0;
}

please... could someone have a look if something is wrong with it please?  ???

I get an error-message while creating the Exe:
main.c(18): error #2168: Operands of == have incompatible types 'unsigned char *' and 'char *'.
« Last Edit: April 15, 2010, 06:06:52 PM by pitter2206 »

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Problem with RegQueryValueEx()
« Reply #1 on: April 15, 2010, 06:51:11 PM »

main.c(18): error #2168: Operands of == have incompatible types 'unsigned char *' and 'char *'.

To compare strings, you need the function strcmp(char *s1, char *s2).

If you want to test it, you can try, if your code works for a PC.

To test your code at your friend you can copy Pelles C on an USB-stick and use the command-line-option /x for POIDE (look into the help, how to use it).

best regards
 Alex ;)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Problem with RegQueryValueEx()
« Reply #2 on: April 15, 2010, 07:20:58 PM »
Is that key under SOFTWARE\GoPal ??
May the source be with you

pitter2206

  • Guest
Re: Problem with RegQueryValueEx()
« Reply #3 on: April 15, 2010, 07:32:16 PM »
Hi timovjl,
no it is as shown under HKLM
« Last Edit: April 15, 2010, 07:38:07 PM by pitter2206 »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Problem with RegQueryValueEx()
« Reply #4 on: April 15, 2010, 07:57:23 PM »
Code: [Select]
if (cDaten[0] == '1')Removed that ';' from line end too
May the source be with you

pitter2206

  • Guest
Re: Problem with RegQueryValueEx()
« Reply #5 on: April 15, 2010, 08:06:49 PM »
YES Sir!!! It works fine!

Thanks a lot!!!