Board index » delphi » RegOpenKeyEx Error!

RegOpenKeyEx Error!

Hi All,
If anyone has used the RegOpenKeyEx  function then can you help me to
resolve the error it is giving me while building the exe.
I am not getting any error while compiling the 'C' program but getting one
while linking or builing an exe.
The error I am geting is with errorcode C2664 and it says that "cannot
convert parameter 2 from 'char[37]' to 'const unsigned short *' at the lines
where i called  RegOpenKeyEx and RegQueryValueEx functions.
I donn't really underastad what's wrong with the code. Also tried the other
way by declaring one veriable with LPCTSTR type.

****************************************************************************
*************
HKEY hKey;
char szFullPath[200];
LPCTSTR  lpSubKey =  "SOFTWARE\\Classes\\FirewallApplication";
DWORD dwBufLen;

RegOpenKeyEx(HKEY_LOCAL_MACHINE,
               "SOFTWARE\\Classes\\FirewallApplication",
               0, KEY_QUERY_VALUE, &hKey ); // alternative way is use
lpSubKey for parameter 2

 RegQueryValueEx(hKey, "FullPath", NULL, NULL,
               (LPBYTE) szFullPath, &dwBufLen);

 RegCloseKey( hKey );

****************************************************************************
**************
Thanks in advance,
Monika

 

Re:RegOpenKeyEx Error!


Hello, Monika!
You wrote  on Tue, 20 Nov 2001 14:17:45 -0000:
[...sorry skipped...]
   It works fine in Borland C++ Builder 5. What ccompiler do you use?

--- markus.

Re:RegOpenKeyEx Error!


Remove the double back-slashes. They are not needed in Delphi.

Here is an example:

procedure SetOptions;
var
  Key:  HKEY;
  szKeyEntry:      array [0..127] of Char;
  szKeyValueName:  array [0..19] of Char;
  szKeyName:       array [0..MAX_PATH] of Char;
  sz:              array [0..MAX_PATH] of char;
begin
  Key := HKEY_LOCAL_MACHINE;
  FillChar(szKeyEntry, SizeOf(szKeyEntry), #0);
  FillChar(szKeyValueName, SizeOf(szKeyEntry), #0);
  szKeyEntry := 'SOFTWARE\MyApp\Settings';
  szKeyName := 'Startup';
  szKeyValueName := 'Yes';
  sz[0] := #0;

  RegOpenKeyEx(Key, szKeyEntry, 0, KEY_ALL_ACCESS, Key);
  RegCreateKeyEx(Key, szKeyEntry, 0, '', REG_SZ, KEY_ALL_ACCESS, nil,
Key, nil);
  RegSetValueEx(Key, szKeyName, 0, REG_SZ, @szKeyValueName,
SizeOf(@sz));

  RegCloseKey(Key);
end;

You can't use NULL in Delphi, it doesn't understand it. Use nil for your
NULL pointer.

Hope this helps.

Ryan

Quote
>Hi All,
>If anyone has used the RegOpenKeyEx  function then can you help me to
>resolve the error it is giving me while building the exe.
>I am not getting any error while compiling the 'C' program but getting one
>while linking or builing an exe.
>The error I am geting is with errorcode C2664 and it says that "cannot
>convert parameter 2 from 'char[37]' to 'const unsigned short *' at the lines
>where i called  RegOpenKeyEx and RegQueryValueEx functions.
>I donn't really underastad what's wrong with the code. Also tried the other
>way by declaring one veriable with LPCTSTR type.

>****************************************************************************
>*************
>HKEY hKey;
>char szFullPath[200];
>LPCTSTR  lpSubKey =  "SOFTWARE\\Classes\\FirewallApplication";
>DWORD dwBufLen;

>RegOpenKeyEx(HKEY_LOCAL_MACHINE,
>               "SOFTWARE\\Classes\\FirewallApplication",
>               0, KEY_QUERY_VALUE, &hKey ); // alternative way is use
>lpSubKey for parameter 2

> RegQueryValueEx(hKey, "FullPath", NULL, NULL,
>               (LPBYTE) szFullPath, &dwBufLen);

> RegCloseKey( hKey );

>****************************************************************************
>**************
>Thanks in advance,
>Monika

Other Threads