how to write an array of little-endian shorts ?

Discussion in 'C++' started by F. Janse Kok, Jun 13, 2004.

  1. F. Janse Kok

    F. Janse Kok Guest

    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
    F. Janse Kok, Jun 13, 2004
    #1
    1. Advertising

  2. F. Janse Kok

    Pete C. Guest

    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
    Pete C., Jun 13, 2004
    #2
    1. Advertising

  3. "F. Janse Kok" <> wrote in message
    news:Xu_yc.8219$...
    >
    > 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
    John Harrison, Jun 13, 2004
    #3
  4. F. Janse Kok

    Frits JK Guest

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

    Regard
    Frits Janse Kok


    "John Harrison" <> schreef in bericht
    news:...
    >
    > "F. Janse Kok" <> wrote in message
    > news:Xu_yc.8219$...
    > >
    > > 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
    >
    >
    Frits JK, Jun 13, 2004
    #4
  5. "Frits JK" <> wrote in message
    news:ig4zc.8462$...
    > 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
    John Harrison, Jun 13, 2004
    #5
  6. "F. Janse Kok" <> wrote in message news:<Xu_yc.8219$>...
    > 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
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Prateek R Karandikar, Jun 14, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hicham
    Replies:
    2
    Views:
    9,005
    dxcoder
    Jul 2, 2003
  2. Ernst Murnleitner

    float: IEEE, big endian, little endian

    Ernst Murnleitner, Jan 13, 2004, in forum: C++
    Replies:
    0
    Views:
    850
    Ernst Murnleitner
    Jan 13, 2004
  3. invincible

    Little Endian to Big Endian

    invincible, Jun 14, 2005, in forum: C++
    Replies:
    9
    Views:
    14,323
    Old Wolf
    Jun 14, 2005
  4. invincible
    Replies:
    1
    Views:
    536
    red floyd
    Jun 14, 2005
  5. gosee
    Replies:
    0
    Views:
    332
    gosee
    Jun 28, 2009
Loading...

Share This Page