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!


In alt.comp.lang.borland-delphi Monika Dongare <monika.dong...@accessdenied.com> wrote:

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

Hi,

the way I see it that RegOpenKeyEx and RegQueryValueEx are needing a WSTR
with WORD (or unsigned short) string. So convert your key name into a WSTR
using MultiByteToWideChar and passing the result as key name to the methods
then all should be right.

Hope it helps.

cu,
Toralf

Re:RegOpenKeyEx Error!


Thanks Toralf,
But it didn't solve the problem and still giving the similar error but this
time it gives while compiling the program itself with same errorcode C2664
as "cannot convert parameter 2 from 'unsigned short[256]' to 'const char *'.
Types pointed to are unrelated".
If you know why is his happening..could you help me again..
Monika

Quote
"Toralf Richter" <t...@irz.inf.tu-dresden.de> wrote in message

news:9tdqaj$gag$1@kastor.inf.tu-dresden.de...
Quote
> In alt.comp.lang.borland-delphi Monika Dongare
<monika.dong...@accessdenied.com> wrote:
> > 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.

****************************************************************************

- Show quoted text -

Quote
> > *************
> > 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 );

****************************************************************************

- Show quoted text -

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

> Hi,

> the way I see it that RegOpenKeyEx and RegQueryValueEx are needing a WSTR
> with WORD (or unsigned short) string. So convert your key name into a WSTR
> using MultiByteToWideChar and passing the result as key name to the
methods
> then all should be right.

> Hope it helps.

> cu,
> Toralf

Other Threads