Sign in to follow this  
johnnyBravo

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

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
you can't impose your own arbitrary decisions on the rest of the programming world.


Look up the word arbitrary. The practice of minimising the use of Macros in both C and C++ code is not arbitrary - it is advocated by the majority of C/C++ programmers for a very good reason.

Quote:

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.


Actually, it's a convention which Microsoft follows for the most part.

Quote:

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.


Rant is your word not mine, so I've no idea why you quoted it.

Secondly, you have no basis for assuming that I've never worked on a large project. I'm well aware that nasty bits of code persist because of the time and effort required to change them.

Quote:

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:)


Microsoft programmers aren't all Herb Sutter.

Quote:

EDIT, sorry that came off alittle harsh on you, didn't mean it to:)


No problem. It's easy to go a little overboard on forums.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nitage
I'm well aware that nasty bits of code persist because of the time and effort required to change them.


"Do you know what 'Legacy Code' means? It's code that works"

It's mostly not there because of the "time and effort required to change them", it's there because Microsoft doesn't own 90% of the code you run everyday, so it can't be changed.

The problem is, if you have Program A which you're running on Windows 2000, and you upgrade to Windows XP which breaks Program A, who do you blame? You don't think to yourself "Crappy Program A developers, everybody knows you're not supposed to call RandomAPI with uninitialized data in the dwReserved parameter of RandomStruct" or whatever, you think "Crappy Windows, breaking this program I've been using for 5 years without a single crash".

So the developers of Windows have to jump through hoops to keep programs running between versions, which means you end up with hacks all over the place...

Share this post


Link to post
Share on other sites
Quote:
Original post by Dean Harding
Quote:
Original post by Nitage
I'm well aware that nasty bits of code persist because of the time and effort required to change them.


"Do you know what 'Legacy Code' means? It's code that works"

It's mostly not there because of the "time and effort required to change them", it's there because Microsoft doesn't own 90% of the code you run everyday, so it can't be changed.

The problem is, if you have Program A which you're running on Windows 2000, and you upgrade to Windows XP which breaks Program A, who do you blame? You don't think to yourself "Crappy Program A developers, everybody knows you're not supposed to call RandomAPI with uninitialized data in the dwReserved parameter of RandomStruct" or whatever, you think "Crappy Windows, breaking this program I've been using for 5 years without a single crash".

So the developers of Windows have to jump through hoops to keep programs running between versions, which means you end up with hacks all over the place...


That's totally wrong. Correcting this would require Microsoft to release a new version of the Win32 API. Legacy code could be compiled with the old version. Applications already compiled would still run.

Much like code compiled for Win98 will run on WinXP even though the API has been expanded.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this