# Newbie in the ocean of windows programming

4 replies to this topic

### #1Boojum

New Member

• Members
• 2 posts

Posted 08 August 2006 - 10:46 AM

Hi everyone
I used to program in C for dos and now decided to learn how to do that for Windows using VC 2005.
Armed with all manuals and help files I could find, I tried to compile a simplest application consisting of WinMain, InitWindow and WndProc(or MsgProc). But it was too easy for programme just to work and it found 3 errors in this part:

bool InitWindow(HINSTANCE hInstance)
{
WNDCLASSEX wc;
...
wc.lpszClassName = "DirectXStuff";     //here be error
RegisterClassEx(&wc);

wndHandle = CreateWindow(
"DirectXStuff",               //error too
"TitleBarMessageWoot!",  //and here
...


Errors were like 'cannot convert from 'const char[13]' to 'LPCWSTR''. Ok, I changed parameters like this:

bool InitWindow(HINSTANCE hInstance)
{
WNDCLASSEX wc;
...
wc.lpszClassName = (LPCTSTR)"DirectXStuff";
RegisterClassEx(&wc);

wndHandle = CreateWindow(
(LPCTSTR)"DirectXStuff",
(LPCTSTR)"TitleBarMessageWoot!",
...


Compiler was satisfied and programme worked at last, though there was still one problem - title bar message was written in some japanese kanji and there's nothing I could do to change it.
Since sample in DirectX SDK worked just great without any manipulations with type, I copy-pasted its code into new project and tried to compile. Guess what, it showed me same errors as in my first application.
It appears to me that answer probably can be in one of those small files in solution folder but comprehending of its content is beyond my level . Tell me please where I can find the answer to that problem (don't want to leave such annoying stuff behind and live with japanese title bars :blush: ).

### #2pater

Valued Member

• Members
• 117 posts

Posted 08 August 2006 - 11:17 AM

It seems your simple example application is being compiled using Unicode character encodings. You can either change the character set (Project Properties->General->Character Set) to Multi-Byte or really use Unicode strings.

wc.lpszClassName = (LPCTSTR)"DirectXStuff";


is a dangerous thing to do: It tells the compiler that "DirectXStuff" is a unicode string, which is obviously wrong. The correct way of declaring an unicode string is

wc.lpszClassName = L"DirectXStuff";


or (even better)

wc.lpszClassName = _T("DirectXStuff");


_T() is a macro that converts to L"" if compiling with unicode or to nothing if not.

### #3jjd

Member

• Members
• 65 posts

Posted 08 August 2006 - 11:22 AM

I suspect that it is your manual and C background that are more the problem here. Firstly, you should try to figure out what the problem actually is rather than just typecasting. I believe the issue is that Windows is trying to use unicode to represent characters because this make it easier to represent text in multiple languages, especially those that don't use the Latin alphabet. Now, I'm not au fait with Windows or unicode so my solution may not be correct, but I use TEXT("Put you text here"). I believe this macro allows the compiler to determine what kind of encoding is available.

Ha! Pater beat me to it! :-) Note, that TEXT is equivalent to the _T macro Pater mentions.
hi, i'm a signature viruz, plz set me as your signature and help me spread :)

### #4tbp

Valued Member

• Members
• 135 posts

Posted 08 August 2006 - 10:21 PM

Another solution is to use "ascii" win32 bindage.

In any case, i mean even if you or your compiling environment have opted for unicode, you can still explicitely access the "ascii" part of the API with the magical 'A' postfix.

As in

WNDCLASSEXA wc;

...

RegisterClassExA(&wc);

...

wndHandle = CreateWindowA(

...



### #5Boojum

New Member

• Members
• 2 posts

Posted 08 August 2006 - 11:00 PM

Thanks a lot guys
I've changed character set to Multi-Byte and it works like a charm, though I'm sure all your advices will come in handy when I start work with text (trying to stick to directX for now ).

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users