how to write an array of little-endian shorts ?

F

F. Janse Kok

I have to write an array of little-endian shorts to the registry of my
pocket-pc
for example the value's 2 , 5 and 10 but I don't know how to work with
chr(0).
In my example below the string stops after the first character.



if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\MSMQ\\SimpleClient\\" , 0, NULL, 0, 0, NULL, &hKey,
&disp)== ERROR_SUCCESS)
{

char MyString[] = "\x02" "\x00" "\x05" "\x00" "\x0A" "\x00" ;
RegSetValueEx(hKey, L"RetrySchedule", 0, REG_BINARY ,
(BYTE*)MyString, strlen(MyString) );

}


Regard,
Frits Janse Kok
 
P

Pete C.

F. Janse Kok said:
I have to write an array of little-endian shorts to the registry of
my pocket-pc
for example the value's 2 , 5 and 10 but I don't know how to work
with chr(0).
In my example below the string stops after the first character.



if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\MSMQ\\SimpleClient\\" , 0, NULL, 0, 0, NULL,
&hKey, &disp)== ERROR_SUCCESS)
{

char MyString[] = "\x02" "\x00" "\x05" "\x00" "\x0A" "\x00"
; RegSetValueEx(hKey, L"RetrySchedule", 0, REG_BINARY ,
(BYTE*)MyString, strlen(MyString) );

}


Regard,
Frits Janse Kok

I think this should work, but not positive: replace strlen(MyString) with
sizeof(MyString).

If you have any more Pocket PC-specific questions, please ask in
microsoft.public.pocketpc.developer. Only Standard C++ is topical in this
group.

- Pete
 
J

John Harrison

F. Janse Kok said:
I have to write an array of little-endian shorts to the registry of my
pocket-pc
for example the value's 2 , 5 and 10 but I don't know how to work with
chr(0).
In my example below the string stops after the first character.



if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\MSMQ\\SimpleClient\\" , 0, NULL, 0, 0, NULL, &hKey,
&disp)== ERROR_SUCCESS)
{

char MyString[] = "\x02" "\x00" "\x05" "\x00" "\x0A" "\x00" ;

That's a bit wierd, since you have a array or char not a string I think its
better to be explicit about it. You might as well make it static and const
at the same time, since that is what you want.

static const char MyString[] = {'\x02', '\x00', '\x05', '\x00',
'\x0A', '\x00'};
RegSetValueEx(hKey, L"RetrySchedule", 0, REG_BINARY ,
(BYTE*)MyString, strlen(MyString) );

(BYTE*)MyString, sizeof MyString );

Again what you have is an array, not a string so use sizeof not strlen.

john
 
F

Frits JK

Thank you both " sizeof(MyString) -1 " was the solution , now
everything is OK.

Regard
Frits Janse Kok


John Harrison said:
F. Janse Kok said:
I have to write an array of little-endian shorts to the registry of my
pocket-pc
for example the value's 2 , 5 and 10 but I don't know how to work with
chr(0).
In my example below the string stops after the first character.



if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\MSMQ\\SimpleClient\\" , 0, NULL, 0, 0, NULL, &hKey,
&disp)== ERROR_SUCCESS)
{

char MyString[] = "\x02" "\x00" "\x05" "\x00" "\x0A" "\x00" ;

That's a bit wierd, since you have a array or char not a string I think its
better to be explicit about it. You might as well make it static and const
at the same time, since that is what you want.

static const char MyString[] = {'\x02', '\x00', '\x05', '\x00',
'\x0A', '\x00'};
RegSetValueEx(hKey, L"RetrySchedule", 0, REG_BINARY ,
(BYTE*)MyString, strlen(MyString) );

(BYTE*)MyString, sizeof MyString );

Again what you have is an array, not a string so use sizeof not strlen.

john
 
J

John Harrison

Frits JK said:
Thank you both " sizeof(MyString) -1 " was the solution , now
everything is OK.

Regard
Frits Janse Kok

-1 because you had a string as your initialiser, so the compiler added a
null byte. If you took my suggestion and used an array initialiser you would
have to drop the -1.

john
 
P

Prateek R Karandikar

F. Janse Kok said:
I have to write an array of little-endian shorts to the registry of my
pocket-pc
for example the value's 2 , 5 and 10 but I don't know how to work with
chr(0).
In my example below the string stops after the first character.



if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\MSMQ\\SimpleClient\\" , 0, NULL, 0, 0, NULL, &hKey,
&disp)== ERROR_SUCCESS)
{

char MyString[] = "\x02" "\x00" "\x05" "\x00" "\x0A" "\x00" ;
RegSetValueEx(hKey, L"RetrySchedule", 0, REG_BINARY ,
(BYTE*)MyString, strlen(MyString) );

}

If you put the above code in int main(), #include all the Standard
Headers before that, and compile it, all you will get is a whole lot
of "undeclared identifier" errors;

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
To iterate is human, to recurse divine.
-L. Peter Deutsch
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top