Click here to Skip to main content
15,890,741 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRezise an CListCtrl on CFormView Pin
mesajflaviu29-Jul-10 20:27
mesajflaviu29-Jul-10 20:27 
AnswerRe: Rezise an CListCtrl on CFormView Pin
mesajflaviu1-Aug-10 22:55
mesajflaviu1-Aug-10 22:55 
QuestionContext Menu and Modelless Dialogs problem Pin
Harsh Shankar29-Jul-10 19:40
Harsh Shankar29-Jul-10 19:40 
QuestionAdd control at runtime? Pin
smengl29-Jul-10 12:30
smengl29-Jul-10 12:30 
AnswerRe: Add control at runtime? Pin
Cool_Dev29-Jul-10 18:02
Cool_Dev29-Jul-10 18:02 
AnswerRe: Add control at runtime? Pin
«_Superman_»29-Jul-10 18:26
professional«_Superman_»29-Jul-10 18:26 
AnswerRe: Add control at runtime? Pin
ThatsAlok7-Jun-11 23:49
ThatsAlok7-Jun-11 23:49 
Questionconvert UCHAR array to UINT array Pin
fasked29-Jul-10 11:29
fasked29-Jul-10 11:29 
Hi!
I need to convert UCHAR array to UINT array.

Example:
        0      8      16     24     32                 0            32
        +------+------+------+------+                  +------------+
INDATA  | 0x11 | 0x22 | 0x33 | 0x44 |  == CONVERT ==>  | 0x11223344 | OUTDATA
        +------+------+------+------+                  +------------+


I have this two functions.
/* put byte to dword */
UINT uchar2uint(UCHAR * in)
{
    return ((*in << 24) | (*(in + 1) << 16) | (*(in + 2) << 8) | *(in + 3)); 
}

/* put byte array to dword array */ 
void uchar2uinta(UCHAR * in, UINT * out, size_t outlen)
{
    while(outlen--)
    {
        *out++ = uchar2uint(in);
        in += 4;
    }
}


int main(void)
{   
    int i;

    UCHAR indata[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
    UINT outdata[2];

    uchar2uinta(indata, outdata, 2);

    for(i = 0; i < 8; ++i)
        printf("%#x ", indata[i]);
    printf("\n");

    for(i = 0; i < 2; ++i)
        printf("%#x ", outdata[i]);
    printf("\n");

    return 0;
}


at the console displays the following text:
0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88
0x11223344 0x55667788


It's OK!
But, i can have a problems, when working in other system with different endianness (big-endian or little-endian)?
May be existed more correct way to convert?

Sorry for my poor English Smile | :)
Best regards, Alexander S.
AnswerRe: convert UCHAR array to UINT array Pin
Peter_in_278029-Jul-10 13:33
professionalPeter_in_278029-Jul-10 13:33 
GeneralRe: convert UCHAR array to UINT array Pin
fasked29-Jul-10 13:39
fasked29-Jul-10 13:39 
AnswerRe: convert UCHAR array to UINT array Pin
Harsh Shankar29-Jul-10 19:51
Harsh Shankar29-Jul-10 19:51 
GeneralRe: convert UCHAR array to UINT array Pin
fasked29-Jul-10 21:03
fasked29-Jul-10 21:03 
GeneralRe: convert UCHAR array to UINT array Pin
Richard MacCutchan29-Jul-10 22:28
mveRichard MacCutchan29-Jul-10 22:28 
QuestionHow to add edit control to CTreeListControl Pin
Sakhalean29-Jul-10 4:00
Sakhalean29-Jul-10 4:00 
AnswerRe: How to add edit control to CTreeListControl Pin
Richard MacCutchan29-Jul-10 5:02
mveRichard MacCutchan29-Jul-10 5:02 
QuestionHow to add Publisher name for an application Pin
Cvaji29-Jul-10 3:46
Cvaji29-Jul-10 3:46 
AnswerRe: How to add Publisher name for an application Pin
Cvaji29-Jul-10 4:10
Cvaji29-Jul-10 4:10 
GeneralRe: How to add Publisher name for an application Pin
Yusuf29-Jul-10 8:57
Yusuf29-Jul-10 8:57 
AnswerRe: How to add Publisher name for an application Pin
Luc Pattyn29-Jul-10 4:12
sitebuilderLuc Pattyn29-Jul-10 4:12 
QuestionClient Connected listbox in vc++ mfc Pin
dilara semerci29-Jul-10 3:30
dilara semerci29-Jul-10 3:30 
AnswerRe: Client Connected listbox in vc++ mfc Pin
Moak29-Jul-10 3:52
Moak29-Jul-10 3:52 
GeneralRe: Client Connected listbox in vc++ mfc Pin
dilara semerci30-Jul-10 2:28
dilara semerci30-Jul-10 2:28 
GeneralRe: Client Connected listbox in vc++ mfc Pin
Moak30-Jul-10 3:35
Moak30-Jul-10 3:35 
QuestionNumber of bytes read coming different while debugging the program and while running it. Pin
learningvisualc28-Jul-10 23:43
learningvisualc28-Jul-10 23:43 
AnswerRe: Number of bytes read coming different while debugging the program and while running it. Pin
Code-o-mat29-Jul-10 0:00
Code-o-mat29-Jul-10 0:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.