abhi312
abhi312

Reputation: 362

UCHAR * to CString conversion and CString to UCHAR * to conversion in vc++

I am new to vc++. How to convert UCHAR * value to CStringand CString to UCHAR *

CString str;
UCHAR * pBuffer;
......Memmory allocation..
str.format(_T("%d"),pBuffer);

But its not working. Second data may be string or int so how to do conversion in proper way.

Upvotes: 0

Views: 721

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596397

Second data may be string or int so how to do conversion in proper way.

You have to interpret the UCHAR* data as a proper data type when formatting it, eg:

// if pBuffer contains 'int' data...
str.format(_T("%d"), *(int*)pBuffer);

// if pBuffer contains 8bit 'char' data w/ a null terminator...
str.format(_T("%hs"), (char*)pBuffer);

Or:

// if pBuffer contains 8bit 'char' data w/o a null terminator...
str.format(_T("%*hs"), iBufferLen, (char*)pBuffer);

And so on...

Upvotes: 1

Related Questions