473,411 Members | 1,899 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,411 software developers and data experts.

how to write an array of little-endian shorts ?


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


Jul 22 '05 #1
5 2538
F. Janse Kok wrote:
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
Jul 22 '05 #2

"F. Janse Kok" <fj*@eb.nl> wrote in message
news:Xu****************@amsnews05.chello.com...

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
Jul 22 '05 #3
Thank you both " sizeof(MyString) -1 " was the solution , now
everything is OK.

Regard
Frits Janse Kok
"John Harrison" <jo*************@hotmail.com> schreef in bericht
news:2j************@uni-berlin.de...

"F. Janse Kok" <fj*@eb.nl> wrote in message
news:Xu****************@amsnews05.chello.com...

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

Jul 22 '05 #4

"Frits JK" <fj*@eb.nl> wrote in message
news:ig***************@amsnews05.chello.com...
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
Jul 22 '05 #5
"F. Janse Kok" <fj*@eb.nl> wrote in message news:<Xu****************@amsnews05.chello.com>...
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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Jul 22 '05 #6

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

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
8
by: Sowen | last post by:
Hi, all I am wondering how to write bits by using ofstream? I have finished a huffman tree, but how can I write the bits to the file in order to gain compression? for example, 'A' returns a...
37
by: Carol Depore | last post by:
How do I determine the maximum array size? For example, int a works, but a does not (run time error). Thank you.
7
by: simkn | last post by:
Hello, I'm writing a function that updates an array. That is, given an array, change each element. The trick is this: I can't change any elements until I've processed the entire array. For...
9
by: steph_de_marseille | last post by:
I would like to write a x array in a file. If the array has a small numbers of columns I know I can use a loop like: int i,j; double array; FILE *file1; file1=fopen("data.dat","w");...
7
by: Marc Bishop | last post by:
Hi can anyone help? I'm making a shopping cart and am stuck on removing an item from my array? The array is made : cArray(ITEM_NAME,cItem) = ProductName
12
by: manochavishal | last post by:
Hi, I have a question. How can i know the size of array when it is passed to a function. For Example i have this code: #include <stdio.h> #include <stdlib.h>
10
by: Pierre Thibault | last post by:
Hello! I am currently trying to port a C++ code to python, and I think I am stuck because of the very different behavior of STL iterators vs python iterators. What I need to do is a simple...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.