Data Conversion

Started by
4 comments, last by Vlarr 21 years, 2 months ago
Is it possible to convert WORD to WCHAR? Reason I asked is because I'm trying to gather information from a task in the MS Task Scheduler using the SYSTEMTIME structure. I would use wprintf() except that I want to display the information using the GDI+ Graphics class DrawString() method but it wants a const WCHAR *string. Is there an easier way to do this or am I just missing the obvious? I've tried countless google searches and the closest I've come is finding how to convert them the other way around. -Vlarr [edited by - Vlarr on January 30, 2003 11:49:57 AM]
~Vlarr
Advertisement
In Win32, at least, the only difference is: WORD is an unsigned short, WCHAR a signed short. You should be able to cast between them without a problem, though I don''t know what will happen with your particular functions.
Access Violation when casting

-Vlarr
~Vlarr
Post the code.
---------------------http://www.stodge.net
/start code

Graphics Gfx(hdc);
SYSTEMTIME NextRunTime;

result = pITask->GetNextRunTime(&NextRunTime);

pITask->Release()

Gfx.DrawString(NextRunTime.wMonth,-1, &fnt, dateText, &whiBrush);

/end code

Obviously the compiler complains about the first parameter of DrawString() but it illustrates what I''m trying to do.

From what I can tell .wMonth is type WORD and the first parameter of DrawString requires const WCHAR*, but casting just brings all sorts of nasty problems. I tried both static_cast and reinterpret_cast.

-Vlarr



~Vlarr
sprintf() it into a char[] array, or use std::string.

Then pass that array/string into the DrawString function.

like:
  char buffer[100];  sprintf(buffer,"NextRunTime: %i",NextRunTime.wMonth);  Gfx.DrawString(buffer,-1, &fnt, dateText, &whiBrush); 

This topic is closed to new replies.

Advertisement