views:

541

answers:

2

I need to convert a UNICODE_STRING structure to a simple NULL TERMINATED STRING.

typedef 
struct _UNICODE_STRING 
{
    USHORT  Length;  
    USHORT  MaximumLength;  
    PWSTR   Buffer;
} 
UNICODE_STRING, *PUNICODE_STRING;

I can't find a clean sollution on MSDN about it. Anyone been there? I am not using .net so I need a native API sollution.

Thanks a lot!

A: 

Take a look at the answers, and even the question, here:

http://stackoverflow.com/questions/117755/is-there-a-faster-way-of-getting-a-char-from-a-variantt-than-const-charbstrt

Corey Trager
+1  A: 

You should use WideCharToMultiByte. As an estimate for the output buffer size, you can use the Length field - but do consider the case of true multi-byte strings, in which case it will fail with ERROR_INSUFFICIENT_BUFFER, and you need to start over with a larger buffer. Or, you call it with an output buffer size of 0 first always, so it tells you the necessary size of the buffer.

Martin v. Löwis