Re: creating registry entry
- From: "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT com>
- Date: Wed, 7 Feb 2007 13:12:11 -0700
I don't know how to make it any clearer. Try to think about what the call
is supposed to do. It puts data OF ANY TYPE AT ALL into the registry. That
is, it might need to put a DWORD type there. Do you think that they only
allow DWORD values less than 255 so you can pass the value as a byte? Of
course not! You pass a pointer to a DWORD, the call looks at the regType
parameter, sees REG_DWORD, and reinterprets the pointer as a pointer to a
DWORD, getting the value. The same basic thing happens when you pass a
REG_SZ or, in your case, a REG_EXPAND_SZ (although I don't see why you're
using that type). The call sees that you've told it that a string is coming
in. Since the call is assuming Unicode strings, it interprets the pointer
as a wchar_t* and gets the string. Ditto for REG_BINARY. There's no way
for the call to somehow magically, at compile time, not generate that
conversion error when it needs to take data of types DWORD*, wchar_t*, and
unsigned char*. That's not the way C/C++ works! So, they pick a generic
pointer type, BYTE*, and you have to cast your pointer to match the declared
type.
Paul T.
<Davep15@xxxxxxxxx> wrote in message
news:1170878104.393712.178020@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I did look at the declaration of RegSetValueEx, it's BYTE (which is a
typedef of unsigned char, what I originally had).
On Feb 7, 1:48 pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT no
instrument no spam DOT com> wrote:
And, if you look at the declaration for RegSetValueEx, you'll see why
that
is. They're expecting a pointer to a byte, since, as you'll note
immediately, RegSetValueEx has to handle setting values of *any* of the
registry data types, everything from REG_SZ, through REG_DWORD, to
REG_BINARY. It has to be a generic parameter!
Paul T.
<Dave...@xxxxxxxxx> wrote in message
news:1170876623.090386.264420@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I actually tried that
TCHAR my_path[20] = L"\\Storage\\my_app.exe";
status =RegSetValueEx(hKey, L"Launch90", 0, REG_EXPAND_SZ, my_path,
40);
and I get an error on compile (yes it's a Unicode compile, why there a
L on the L"Launch90")
error C2664: 'RegSetValueExW' : cannot convert parameter 5 from
'unsigned short [20]' to 'const unsigned char *'
On Feb 7, 12:50 pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
unsigned char? The registry API and virtually every other API in
Windows
CE
is Unicode based, not ASCII based. Make your my_path[] variable look
like
this:
TCHAR my_path[] = _T( "\\Storage\\my_app.exe" );
Don't forget to set the Depends key for your application, too...
Paul T.
<Dave...@xxxxxxxxx> wrote in message
news:1170871795.371371.323350@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm trying to create a registry entry to boot my app at system
startup
(yes I want/need to do it in the registry). It creates an entry OK
but
it's not of the string type. I've tried a few different modifiers
for
the type, some do make it string but it's not the correct data.
Please
help. Here's what I have...
HKEY hKey;
DWORD status;
DWORD Disposition;
status = RegCreateKeyEx(HKEY_LOCAL_MACHINE, L"init", 0, NULL, 0, 0,
0, &hKey, &Disposition );
if (status != ERROR_SUCCESS) {
TCHAR err[40];
wsprintf(err,L"Registry Open/Create Error %i",status);
MessageBox(NULL, err,L"",NULL);
return;
}
unsigned char my_path[20] = "\\Storage\\my_app.exe";
status =RegSetValueEx(hKey, L"Launch90", 0, REG_EXPAND_SZ, my_path,
20);
if (status != ERROR_SUCCESS) {
TCHAR err[40];
wsprintf(err,L"Registry Write Error (1) %i",status);
MessageBox(NULL, err,L"",NULL);
return;
}
.
- References:
- creating registry entry
- From: Davep15
- Re: creating registry entry
- From: Paul G. Tobey [eMVP]
- Re: creating registry entry
- From: Davep15
- Re: creating registry entry
- From: Paul G. Tobey [eMVP]
- Re: creating registry entry
- From: Davep15
- creating registry entry
- Prev by Date: Re: creating registry entry
- Next by Date: Re: setsockopt and IP_MULTICAST_LOOP
- Previous by thread: Re: creating registry entry
- Next by thread: Re: Help Installing eVC4 please
- Index(es):
Relevant Pages
|