c++ Why am I getting CreateWindowW, when I call CreateWindow ?

Started by
11 comments, last by Nitage 18 years, 10 months ago
Hi, i've got two projects, with the same code. One was created from the Visual c++ 2005 beta 1, and the other was created in beta 2 version. With the beta1, when I call 'CreateWindow', which is when I put my mouse over it, says 'CreateWIndowA' has been defined as 'CreateWindow'. But with beta2 the 'CreateWindow' has been defined as 'CreateWindowW'. I've looked through the two different project files, and I can't see any major differences that would cause the two projects to get a different definition of the 'CreateWindow' function. Anyone know what is going on here? Thanks
Advertisement
CreateWindow is (along with many other Win32 functions) mapped to one of two functions, CreateWindowA or CreateWindowW, depending on whether or not UNICODE has been defined. Your project in beta2 apparently has unicode defined, so you're getting the wide character version of the function. I'm away from my own computer right now, but some googling says you should be able to remove the unicode flag by doing the following:

-Look under Project Settings -> C/C++ tab -> Category: General -> Preprocessor Definitions
-Remove UNICODE and/or _UNICODE
Quote:Original post by Nemesis2k2
CreateWindow is (along with many other Win32 functions) mapped to one of two functions, CreateWindowA or CreateWindowW, depending on whether or not UNICODE has been defined.

winuser.h:
#ifdef UNICODE
#define CreateWindow CreateWindowW
#else
#define CreateWindow CreateWindowA
#endif // !UNICODE

Quote:Original post by Nemesis2k2
...to remove the unicode flag by doing the following:

Sure, but there's really no good reason to do this, unless you need to run on Windows 9x.

Windows NT/2000/XP and upcoming versions of Windows are all natively designed for Unicode.

CreateWindowW is the actual implementation, CreateWindowA is only a wrapper that converts CHAR strings to WCHAR strings and then calls CreateWindowW. This holds for all Win32 APIs that has both A and W versions. So from a performance point of view it's better to use the WCHAR versions. Of course it also makes your applications easier to localize.
Article about Unicode/WinAPI
Read chapter 2 of Charles Petzold's "Programming Windows". It explains the situation and rationale for _UNICODE quite well.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Macros. Yuck. This really annoys me when creating OO wrappers around the Win32 API. They didn't even bother with the all caps naming convention for macros.
Quote:Original post by Nitage
Macros. Yuck. This really annoys me when creating OO wrappers around the Win32 API. They didn't even bother with the all caps naming convention for macros.


Well its nice you think this way:) but the win32 api is C not C++, you can't impose your own arbitrary decisions on the rest of the programming world. The reason they don't use the all caps naming convention is two fold a) its just your convention not a standard, b) they wan't it to look like a funtion call as that's how it was from the windows 3.1 days. This way other people dont' have to modify their code.

Just because you've never worked on a serious project doesn't mean others haven't. Maintaing legacy code is very important, and your "rant" would cause most of it to break.

EDIT, sorry that came off alittle harsh on you, didn't mean it to:) You just need to learn that most microsoft "hacks" are acutallly very well thought out and implemented by people who have forgotten more about programming than we'll ever know:)

Cheers
Chris
CheersChris
Good post [smile]

Quote:Original post by chollida1
You just need to learn that most microsoft "hacks" are acutallly very well thought out and implemented by people who have forgotten more about programming than we'll ever know
[lol] I presume you didn't mean "forgotten" in that sentence?! Either way it's funny, you get a cookie.

Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

That's a common saying - think Grandpa Simpson voice:
"Listen here sonny, I've forgotten more than you'll ever know!"

It took me about 26 years before I really started listening to my dad. Hopefully it won't take other people quite so long.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Quote:
Quote:Original post by Nemesis2k2
...to remove the unicode flag by doing the following:

Sure, but there's really no good reason to do this, unless you need to run on Windows 9x.

Windows NT/2000/XP and upcoming versions of Windows are all natively designed for Unicode.

He'd already posted with problems created by this. I was trying to just give him what he wanted and avoid a followup post. A bit lazy on my behalf I'll grant you, but anyway.

Quote:CreateWindowW is the actual implementation, CreateWindowA is only a wrapper that converts CHAR strings to WCHAR strings and then calls CreateWindowW. This holds for all Win32 APIs that has both A and W versions. So from a performance point of view it's better to use the WCHAR versions.

I didn't know that; thanks for the tip.

This topic is closed to new replies.

Advertisement