GetCurrentTime (p)redefined by winbase.h-.-

Huhu...

I have an member function of my Manager Class named "GetCurrentTime()"...
Also, I have <windows.h> included, which resolves in a problem:

because it includes <winbase.h> itself there is an #define GetTickCount() GetCurrentTime() ...

the problem now is, that i do not want to rename or search-and-replace the GetCurrentTime()-member of my class...

is there another solution? (WIN32_LEAN_AND_MEAN does ofcourse not work)...
this is one of the many reasons why macros are evil.

Anyway you can #undef it:

1
2
3
4
5
6
7
8
#ifdef GetCurrentTime
#undef GetCurrentTime
#endif

class Manager
{
   whatever GetCurrentTime();  // now it's OK
};


EDIT:

of course, this will introduce problems if you want to use WinAPI's GetCurrentTime function.
Last edited on
i am wondering why this works even while the inclusion of the winbase.h is in another class header file and the undef in this one...

i always did try to do it right in the cpp file which needed the function of mine...
wait.. what? I'm not sure I understand.

It should work as long as you undef after the #include, and before you actually use the function.
I have it like the following: (now as it works)...

class.h

1
2
3
4
5
6
7
8
#ifdef GetCurrentTime
#undef GetCurrentTime
#endif

class Manager
{
//BlaBlubb
};


class.cpp
1
2
3
4
5
6
7
#include "class.h"
#include //some other file which includes windows.h

rettype class::TheFunction()
{
//Blabla GetCurrentTime();
}
I'm not sure that would really work.

If you #include <windows.h> after you #include class.h, windows.h will #define GetCurrentTime again, and all references to it in class.cpp will screw up again.

I would #include class.h after all your other includes
Topic archived. No new replies allowed.