Public Group

# How to get around thoes system defines

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

## 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 on other sites
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 on other sites
Quote:
 Original post by Evil SteveSo 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 on other sites
Quote:
Original post by mattd
Quote:
 Original post by Evil SteveSo 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 on other sites
I guess the only way around is to not use CreateFile. What would be the purpose of your class? Maybe there are better names anyways?

##### 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 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 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 on other sites
Quote:
 Original post by littlekidThanks 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 on other sites
Quote:
Original post by phresnel
Quote:
 Original post by littlekidThanks 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 =)

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 98
• 11
• ### Forum Statistics

• Total Topics
632974
• Total Posts
3009654
• ### Who's Online (See full list)

There are no registered users currently online

×