• Advertisement
Sign in to follow this  

How to get around thoes system defines

This topic is 3092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I am facing a problem with thoes defines by the system header files such as winbase.h I have a method in a class: class MyClass { public: void CreateFile(); }; However in winbase.h CreateFile is define to be CreateFileW due to the unicode stuff. And being a #define thing, it is making my method name change too. Is there anyway to avoid this problem, other than changing my method name? I understand that i can #undef it, but that would cause problems to people who wishes to use the actual CreateFile function by windows.

Share this post


Link to post
Share on other sites
Advertisement
This is just one of those annoying things unfortunately.

So long as you #include your header before any Windows headers, you'll be fine - but you need to ensure that the users of your class do the same.
EDIT: Ignore that, see mattd's point below.

Personally, I'd rename the method if possible. In this case, perhaps something a little more descriptive would be better, such as CreateSettingsFile()?

[Edited by - Evil Steve on November 6, 2009 4:29:48 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
So long as you #include your header before any Windows headers, you'll be fine - but you need to ensure that the users of your class do the same.

#include "MyClass.h"
#include <windows.h>

int main() {
MyClass c;
c.CreateFile();
}
?

Share this post


Link to post
Share on other sites
Quote:
Original post by mattd
Quote:
Original post by Evil Steve
So long as you #include your header before any Windows headers, you'll be fine - but you need to ensure that the users of your class do the same.

#include "MyClass.h"
#include <windows.h>

int main() {
MyClass c;
c.CreateFile();
}
?
Ah yes, I'm an idiot - ignore that bit...

Share this post


Link to post
Share on other sites
You can also make sure you always #include <windows.h> before anything else (e.g. by putting in a precompiled header). That way, CreateFile will still become CreateFileW, but at least it'll be consistent :-)

You can also get around it with a non-CamelCase naming convention, but that might be a bit much to ask...

Share this post


Link to post
Share on other sites
I think using a better name is the best solution.

Would it also be possible to use #undef CreateFile in your class
header file? Although this may have other repurcussions that I
am unaware of.

Share this post


Link to post
Share on other sites
Thanks for the replies :), i guess i have to change my method name. Ahh i hope windows put all their functions in a namespace or something that can solve this problem =)

Share this post


Link to post
Share on other sites
Quote:
Original post by littlekid
Thanks for the replies :), i guess i have to change my method name. Ahh i hope windows put all their functions in a namespace or something that can solve this problem =)


You cannot solve #define aches with namespaces =(

Share this post


Link to post
Share on other sites
Quote:
Original post by phresnel
Quote:
Original post by littlekid
Thanks for the replies :), i guess i have to change my method name. Ahh i hope windows put all their functions in a namespace or something that can solve this problem =)


You cannot solve #define aches with namespaces =(


hmm idiot me, thats true. hmm...well would something like that work??

like:

namespace windows_system_a
{
void CreateFile(char* );
};

namespace windows_system_w
{
void CreateFile(wchar_t* );
};

#ifndef UNICODE
#define windows_system windows_system_a
#else
#define windows_system windows_system_w
#endif

I am not sure if this works, but maybe it can greatly reduce the number of defines?? and there won't be so many clashes with the windows files =)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement