• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Data Conversion

## Recommended Posts

Vlarr    122
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]

##### Share on other sites
sbennett    124
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.

##### Share on other sites
Vlarr    122
Access Violation when casting

-Vlarr

stodge    144
Post the code.

##### Share on other sites
Vlarr    122
/start code

Graphics Gfx(hdc);
SYSTEMTIME NextRunTime;

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

##### Share on other sites
TravisWells    276
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);