Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how to write an array of little-endian shorts ?

Reply
Thread Tools

how to write an array of little-endian shorts ?

 
 
F. Janse Kok
Guest
Posts: n/a
 
      06-13-2004

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




 
Reply With Quote
 
 
 
 
Pete C.
Guest
Posts: n/a
 
      06-13-2004
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


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      06-13-2004

"F. Janse Kok" <(E-Mail Removed)> wrote in message
news:Xu_yc.8219$(E-Mail Removed)...
>
> 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


 
Reply With Quote
 
Frits JK
Guest
Posts: n/a
 
      06-13-2004
Thank you both " sizeof(MyString) -1 " was the solution , now
everything is OK.

Regard
Frits Janse Kok


"John Harrison" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
>
> "F. Janse Kok" <(E-Mail Removed)> wrote in message
> news:Xu_yc.8219$(E-Mail Removed)...
> >
> > 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
>
>



 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      06-13-2004

"Frits JK" <(E-Mail Removed)> wrote in message
news:ig4zc.8462$(E-Mail Removed)...
> 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


 
Reply With Quote
 
Prateek R Karandikar
Guest
Posts: n/a
 
      06-14-2004
"F. Janse Kok" <(E-Mail Removed)> wrote in message news:<Xu_yc.8219$(E-Mail Removed)>...
> 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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Abercrombie Fitch Beach Shorts - Abercrombie Fitch Mens Shorts gosee C Programming 0 06-28-2009 08:57 AM
Set shorts out after 2-3 hours, why? Wereo_SUPREME Computer Support 14 04-19-2007 12:41 PM
Umiversal guy in green shorts Dyuob Poltice DVD Video 1 10-07-2004 06:46 AM
New Releases: WB announcements, Oscar Shorts & Status changes: Updated complete downloadable R1 DVD DB & info lists Doug MacLean DVD Video 0 01-03-2004 05:22 AM



Advertisments