473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Write Registry, missing some hex

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

Aug 14 '07 #1
8 2869
On 2007-08-14 10:40, Kniffel wrote:
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.

--
Erik Wikström
Aug 14 '07 #2
Ok
thanks
i will try it then in a other group...

Aug 14 '07 #3
Hi!

Apart from the offtopic issue I spotted something which might be a bug.

Kniffel schrieb:
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
Aug 14 '07 #4
On 14 Aug., 11:11, Frank Birbacher <bloodymir.c...@gmx.netwrote:
Hi!

Apart from the offtopic issue I spotted something which might be a bug.

Kniffel schrieb:
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?

Aug 14 '07 #5
Hi!

Kniffel schrieb:
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
Aug 14 '07 #6
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

Aug 14 '07 #7
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];"?

Aug 14 '07 #8
Hi!

Kniffel schrieb:
>const DWORD sizeOfSubkeyValue = sizeof(lpstrSubkeyValue) /
sizeof(*lpstrSubkeyValue);

This gives me a size of 510...
Probably because MAX_PATH is that large.

Frank
Aug 14 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: benjamin schollnick | last post by:
Folks, I am having difficulty with *reading* the registry from a remote Windows box... 1) I need to impersonate a different user name & password, then the user I am currently logged in as....
1
by: DC Gringo | last post by:
I have some code that writes log entries upon errors in an VB.NET web app. I can write the Message but in the log, preceding my message is the following: Description: The description for...
1
by: firenet | last post by:
Came in one morning and found that the following message appeared only on running Access 2000, then the program shuts down, all other office 2000 applications work fine. "Required registry...
3
by: caldera | last post by:
Hi, I write a windows service. In that service I create a new subkey for registry. But service install is call CreateSubKey() the program throw an exception to the event log said that Cannot write...
2
by: Dan Sikorsky | last post by:
Should application data be read and written to the Registry to persist state, or should the App.config file be used? If the Registry should be used, what .NET class reads and writes the...
5
by: Chakkaradeep | last post by:
Hi all, in my service i added my Registry Programming code,am facing with a problem which am not able to rectify it..the problem is , in the service, the program gets hanged and doesnt move...
6
by: CMG | last post by:
I am writing a little code to associate an extention with my program. And as far as i can see, i need to do the following: Public Function associatefile(ByVal FILE_EXTENTION_TO_ASSOCIATE As...
9
by: nbs.tag | last post by:
hey guys heres my question. I was told by a little birdie that .net 2.0 has the ability to read a connection string directly from a registry key. so in the registry key a string value of say :...
0
by: Michael Fay in SB | last post by:
A month ago I posted: "I built my application with Access 2003 and made a distribution using the Microsoft Office Access 2003 Developer Extensions. (I also install Jet 8 as a follow-on action at...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.