Code Repo    |     RSS
MD's Technical Sharing



Thursday, April 9, 2009

Useful Conversion in C++

BYTE[] to DWORD:

BYTE tzValue[4];

DWORD value = tzValue[3]*16*16*16 + tzValue[2]*16*16 + tzValue[1]*16 + tzValue[0];


Print hexadecimal:

printf("Value: 0x%08lx\n", value);


BYTE[] to WCHAR:

BYTE tzValue[MAX_PATH];

WCHAR* strDest = (WCHAR*) &tzValue[0];


Merge 2 WORDs into a DWORD:

WORD wLow;

WORD wHigh;

DWORD dw = wLow + 0x1000*wHigh;


BSTR to (char*)

BSTR st;

char* st = (const char*)_bstr_t(st);



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.