Write Registry, missing some hex

K

Kniffel

hi everyone

I programm an ISAPI extension with embedded Visual C++ for a Windows
CE device.
I try to write the network settings to the registry.
I am able to write the IpAdress to the registry, but when I compare my
registry entry and the one made with the Windows CE settings, I miss
some hex chars:

The Way I write my registry entry:
LONG iSuccess = RegCreateKeyEx( HKEY_LOCAL_MACHINE, lpstrKey, 0L,NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);

if(iSuccess == ERROR_SUCCESS) {
lpstrSubkey = L"IpAddress";
MultiByteToWideChar(CP_ACP, 0, NetValueArray[queryCounter], -1,
lpstrSubkeyValue, sizeof(lpstrSubkeyValue));
/**** WRITE A HEX VALUE IN REGISTRY ****/
DWORD dwDispHex = 0;
LPDWORD lpdwDispHex = &dwDispHex;

iSuccess = RegCreateKeyEx( HKEY_LOCAL_MACHINE, lpstrKey,
0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKey,lpdwDispHex);
if(iSuccess == ERROR_SUCCESS)
{
RegSetValueEx(hKey, lpstrSubkey, 0, REG_MULTI_SZ,
(LPBYTE)lpstrSubkeyValue, strlen(NetValueArray[queryCounter])*2);
}
}

This results in this Registry Entry:
"IpAddress"=hex(7):\
31,32,33,2e,31,32,33,2e,31,32,33,2e,31,32,33

The same Registry Entry made in the Windows CE settings looks like
that:
"IpAddress"=hex(7):\
31,32,33,2e,31,32,33,2e,31,32,33,2e,31,32,33,00,00

What kind of hexchar is 00?
And how can I add this to my registry entry?

Greetings
Thomas
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

hi everyone

I programm an ISAPI extension with embedded Visual C++ for a Windows
CE device.
I try to write the network settings to the registry.
I am able to write the IpAdress to the registry, but when I compare my
registry entry and the one made with the Windows CE settings, I miss
some hex chars:

The Way I write my registry entry:
LONG iSuccess = RegCreateKeyEx( HKEY_LOCAL_MACHINE, lpstrKey, 0L,NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);

if(iSuccess == ERROR_SUCCESS) {
lpstrSubkey = L"IpAddress";
MultiByteToWideChar(CP_ACP, 0, NetValueArray[queryCounter], -1,
lpstrSubkeyValue, sizeof(lpstrSubkeyValue));
/**** WRITE A HEX VALUE IN REGISTRY ****/
DWORD dwDispHex = 0;
LPDWORD lpdwDispHex = &dwDispHex;

iSuccess = RegCreateKeyEx( HKEY_LOCAL_MACHINE, lpstrKey,
0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKey,lpdwDispHex);
if(iSuccess == ERROR_SUCCESS)
{
RegSetValueEx(hKey, lpstrSubkey, 0, REG_MULTI_SZ,
(LPBYTE)lpstrSubkeyValue, strlen(NetValueArray[queryCounter])*2);
}
}

This results in this Registry Entry:
"IpAddress"=hex(7):\
31,32,33,2e,31,32,33,2e,31,32,33,2e,31,32,33

The same Registry Entry made in the Windows CE settings looks like
that:
"IpAddress"=hex(7):\
31,32,33,2e,31,32,33,2e,31,32,33,2e,31,32,33,00,00

What kind of hexchar is 00?

00 is 00 is 0 is 0x0.
And how can I add this to my registry entry?

Sorry, but this is off-topic in here, this group is for discussing the
C++ language as defined by the standard, third party libraries should be
discussed in their own groups. Try to post in either

comp.os.ms-windows.programmer.win32 or one of the microsoft.public.*
groups to get in contact with the windows experts.
 
A

Alf P. Steinbach

* Kniffel:
[OFF-TOPIC]

Even though your question is off-topic in this group, please don't feel
unwelcome. Spend some time reading posted articles to familiarize
yourself with the group, read the FAQ. The FAQ also gives good advice
about relevant groups where you can post your Windows programming
question (the only advice relevant in this group, is to use C++ 'bool',
'true' and 'false' rather than macros for completely different purpose).

C U L8R,

- Alf
 
F

Frank Birbacher

Hi!

Apart from the offtopic issue I spotted something which might be a bug.
MultiByteToWideChar(CP_ACP, 0, NetValueArray[queryCounter], -1,
lpstrSubkeyValue, sizeof(lpstrSubkeyValue));

If "lpstrSubkeyValue" is an array, forget my post.

I guess "lpstrSubkeyValue" is a mere pointer (to wide chars). Thus
"sizeof(lpstrSubkeyValue)" will probably return 4. Demonstration:

char* lpstrFoo = "Foobarbaz";
std::cout << sizeof(lpstrFoo); //propably prints "4"
lpstrFoo[2] = 'A'; //not allowed, undefined behaviour

Frank
 
K

Kniffel

Hi!

Apart from the offtopic issue I spotted something which might be a bug.
MultiByteToWideChar(CP_ACP, 0, NetValueArray[queryCounter], -1,
lpstrSubkeyValue, sizeof(lpstrSubkeyValue));

If "lpstrSubkeyValue" is an array, forget my post.

I guess "lpstrSubkeyValue" is a mere pointer (to wide chars). Thus
"sizeof(lpstrSubkeyValue)" will probably return 4. Demonstration:

char* lpstrFoo = "Foobarbaz";
std::cout << sizeof(lpstrFoo); //propably prints "4"
lpstrFoo[2] = 'A'; //not allowed, undefined behaviour

Frank

Yes it returns 4.
The var is defined like that: WCHAR lpstrSubkeyValue[MAX_PATH+1];

How i get the size I should insert here?
 
F

Frank Birbacher

Hi!
The var is defined like that: WCHAR lpstrSubkeyValue[MAX_PATH+1];

How i get the size I should insert here?

Here sizeof(lpstrSubkeyValue) should not return 4. It should return the
size in bytes (actually the unit is sizeof(char), which is 1 on windows)
of the array. To get the number of elements which you need to pass to
that funtion you need to divide this by the size of a single element:

const DWORD sizeOfSubkeyValue = sizeof(lpstrSubkeyValue) /
sizeof(*lpstrSubkeyValue);

Here "*lpstrSubkeyValue" is the first element of the array. Now just
pass sizeOfSubkeyValue to the function.

Frank
 
A

Alf P. Steinbach

* Kniffel:
The var is defined like that: WCHAR lpstrSubkeyValue[MAX_PATH+1];

If you're going to use unreadable Microsoft Hungarian prefixes, at least
use them correctly, please.

You're not declaring "long pointer to string", lpstr.

Even better, get rid of that Hungarian notation.
 
K

Kniffel

const DWORD sizeOfSubkeyValue = sizeof(lpstrSubkeyValue) /
sizeof(*lpstrSubkeyValue);

This gives me a size of 510... this is way to much. And my registry
value contains things I don´t want.

My calculation gives the correct size, I added "+1" since the first
post:
(strlen(NetValueArray[queryCounter])*2)+1
 
K

Kniffel

The var is defined like that: WCHAR lpstrSubkeyValue[MAX_PATH+1];
If you're going to use unreadable Microsoft Hungarian prefixes, at least
use them correctly, please.

You're not declaring "long pointer to string", lpstr.

Even better, get rid of that Hungarian notation.

You mean to just write "WCHAR SubkeyValue[MAX_PATH+1];"?
 
A

Alf P. Steinbach

* Kniffel:
The var is defined like that: WCHAR lpstrSubkeyValue[MAX_PATH+1];
If you're going to use unreadable Microsoft Hungarian prefixes, at least
use them correctly, please.

You're not declaring "long pointer to string", lpstr.

Even better, get rid of that Hungarian notation.

You mean to just write "WCHAR SubkeyValue[MAX_PATH+1];"?

Essentially yes.

But even better, just

wchar_t SubkeyValue[MAX_PATH+1];

No need to use the platform-specific macro.

<OT, please take discussion of this point to Microsoft group>
Since you're using Unicode in Windows, a path can be considerably longer
than MAX_PATH; it can be up to approximately 30000 characters long.
Whether you need that or not depends on whether you're actually storing
paths, and if so, how those path values are acquired.
</OT>


Follow-ups set to [comp.os.ms-windows.programmer.win32].

Cheers,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top