Skip to main content
GameDev.net gamedev.net
🔒 Locked

UNICODE and textout problems

Started by PPCThug Apr 19, 2004 at 5:04 PM 5 replies 700+ views
Original Post
PPCThug
PPCThug
I''m writing a simple program that prints single charecters, I tried to convert it to unicode but I get an error in textout function that says cannot convert wchar_t to constant char, ok thats simple enough, textout doesn''t like data types other than char. so should I be using a wide charecter version of textout that I couldn''t find or am I missing somthing? this is the important parts of the code I think, if you want it all just say so

#include <windows.h>
#include <string>
#include <tchar.h> // don''t think I need this, I was wrong.


#define UNICODE


LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

    HDC         hdc ;
    PAINTSTRUCT ps ;
    TEXTMETRIC  tm ;
    // TCHAR       szBuffer [4] ; // don''t think I need this

    
    static wchar_t wcText = ''a'';


                  TextOut (hdc, cixPlace, ciyPlace, &wcText, 1) ;

[source/]

Bloodshed Dev-C++ 4.9.8.0 Mingw DX 9.0a DX SDK 6.1 win2k #define WIN32_LEAN_AND_MEAN the Particle Projection Cannon fires a shimmering blue bolt, much like a cross between lightning and a sine wave that ripples along its path. mechwarrior 2 mercenaries, 4 particle projection cannons, thug chassis
Bloodshed Dev-C++ 4.9.8.0 Mingw DX 9.0a DX SDK 6.1win2k#define WIN32_LEAN_AND_MEANthe Particle Projection Cannon fires a shimmering blue bolt, much like a cross between lightning and a sine wave that ripples along its path.mechwarrior 2 mercenaries, 4 particle projection cannons, thug chassis
SiCrane
SiCrane
Did you try defining UNICODE in the project settings or moving the #define to before the point you include windows.h?
PPCThug
PPCThug
puting #define UNICODE before #include <windows.h> caused a lot of problems, and I''m not sure how or where define unicode would go in project settings
Bloodshed Dev-C++ 4.9.8.0 Mingw DX 9.0a DX SDK 6.1win2k#define WIN32_LEAN_AND_MEANthe Particle Projection Cannon fires a shimmering blue bolt, much like a cross between lightning and a sine wave that ripples along its path.mechwarrior 2 mercenaries, 4 particle projection cannons, thug chassis
mmal
mmal
When defining UNICODE under windows, you should also define _UNICODE because the windows headers uses both... atleast it worked for me when I had the same problems.

Oh, and ofcourse the UNICODE defines should come before the #include <windows.h>, else the compiler would have no way of knowing if it should use the wchar versions of the windows functions

[edited by - mmal on April 19, 2004 7:10:09 PM]
PPCThug
PPCThug
so now I have

#define UNICODE
#define _UNICODE

#include <windows.h>
#include <string>
#include <tchar.h>

while

wchar_t szClassName[ ] = _TEXT ("WindowsApp");

and

szClassName, /* Classname */
_TEXT ("Charecter Display"), /* Title Text */

fixed the errors that came up
Bloodshed Dev-C++ 4.9.8.0 Mingw DX 9.0a DX SDK 6.1win2k#define WIN32_LEAN_AND_MEANthe Particle Projection Cannon fires a shimmering blue bolt, much like a cross between lightning and a sine wave that ripples along its path.mechwarrior 2 mercenaries, 4 particle projection cannons, thug chassis
psykr
psykr
quote:
Original post by PPCThug
wchar_t szClassName[ ] = _TEXT ("WindowsApp");

Careful, wchar_t specifies that you're using wide characters, while the _TEXT() macro specifies that you switch between wide and narrow strings according to whether UNICODE is #define'd. You should stick to one or the other:

// for full wide character usage
wchar_t szClassName[] = L"WindowsApp";


// for "switchability" (for lack of a better word)
TCHAR szClassName[] = _TEXT("WindowsApp");


[edited by - psykr on April 19, 2004 9:22:06 PM]
PPCThug
PPCThug
oh, ok thanks
Bloodshed Dev-C++ 4.9.8.0 Mingw DX 9.0a DX SDK 6.1win2k#define WIN32_LEAN_AND_MEANthe Particle Projection Cannon fires a shimmering blue bolt, much like a cross between lightning and a sine wave that ripples along its path.mechwarrior 2 mercenaries, 4 particle projection cannons, thug chassis

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.