Function name clashing with MACRO
-
Not really a big problem since I could just rename my function, but nontheless, I would like to know how to correctly deal with this. I have a class with a member function:
virtual HWND CreateWindow( DWORD dwStyle, HWND hWndParent );
No prizes for guessing what the derived class should do :laugh: Upon compile, it clashes with theCreateWindow
macro giving me an error:warning C4003: not enough actual parameters for macro 'CreateWindowW' error C2059: syntax error : 'constant'
Would somebody be kind enough to help me out with this as I really really want to keep that function name. -
Not really a big problem since I could just rename my function, but nontheless, I would like to know how to correctly deal with this. I have a class with a member function:
virtual HWND CreateWindow( DWORD dwStyle, HWND hWndParent );
No prizes for guessing what the derived class should do :laugh: Upon compile, it clashes with theCreateWindow
macro giving me an error:warning C4003: not enough actual parameters for macro 'CreateWindowW' error C2059: syntax error : 'constant'
Would somebody be kind enough to help me out with this as I really really want to keep that function name. -
cpallini wrote:
#undef CreateWindow
] that will no do!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you
-
Not really a big problem since I could just rename my function, but nontheless, I would like to know how to correctly deal with this. I have a class with a member function:
virtual HWND CreateWindow( DWORD dwStyle, HWND hWndParent );
No prizes for guessing what the derived class should do :laugh: Upon compile, it clashes with theCreateWindow
macro giving me an error:warning C4003: not enough actual parameters for macro 'CreateWindowW' error C2059: syntax error : 'constant'
Would somebody be kind enough to help me out with this as I really really want to keep that function name.WalderMort wrote:
virtual HWND CreateWindow( DWORD dwStyle, HWND hWndParent );
could you show us the code of calling of CreateWindow function
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you
-
cpallini wrote:
#undef CreateWindow
] that will no do!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you
-
My 4mb connection is running at 2k again today :mad: I thought about the #undef method, but I would then need to define it again after the function. Redefining involves checking the UNICODE and using the correct function, in doing so what's to say the origional macro will not change after a few months. For now I have simply renamed the function to GetWindow(), but this is confusing within my personal naming schemes. You also asked for a code sample of how it's called:
m_hWnd = GetWindow( dwStyle, hParent );
if ( ! m_hWnd )
throw _T("Unable to create window");// Set the windows size and position
BOOL bSuccess = FALSE;
bSuccess = SetWindowPos(m_hWnd,NULL,uLeft,uTop,uWidth,uHeight,SWP_NOZORDER|SWP_NOSENDCHANGING);The derived class would then call the orgional CreateWindow() macro/function to creat a certain type of window ( window class ) and return it's handle. [APPEND] Oops, I replied to the wrong poster. This message is aimed at ThatsAllOk :rose:
-
I think that after un-defining the definition, the original
CreateWindow
functions from Windows API will not be more available inside the implementation of the otherCreateWindow
member. -
My 4mb connection is running at 2k again today :mad: I thought about the #undef method, but I would then need to define it again after the function. Redefining involves checking the UNICODE and using the correct function, in doing so what's to say the origional macro will not change after a few months. For now I have simply renamed the function to GetWindow(), but this is confusing within my personal naming schemes. You also asked for a code sample of how it's called:
m_hWnd = GetWindow( dwStyle, hParent );
if ( ! m_hWnd )
throw _T("Unable to create window");// Set the windows size and position
BOOL bSuccess = FALSE;
bSuccess = SetWindowPos(m_hWnd,NULL,uLeft,uTop,uWidth,uHeight,SWP_NOZORDER|SWP_NOSENDCHANGING);The derived class would then call the orgional CreateWindow() macro/function to creat a certain type of window ( window class ) and return it's handle. [APPEND] Oops, I replied to the wrong poster. This message is aimed at ThatsAllOk :rose:
WalderMort wrote:
he derived class would then call the orgional CreateWindow() macro/function to creat a certain type of window ( window class ) and return it's handle.
My personnel belief, always try not to use Actual Window api name in your classes.. as it might confused other programmer.... here GetWindow can again create problem... better change it name to CreateMyWindow.. etc..
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you
-
Not really a big problem since I could just rename my function, but nontheless, I would like to know how to correctly deal with this. I have a class with a member function:
virtual HWND CreateWindow( DWORD dwStyle, HWND hWndParent );
No prizes for guessing what the derived class should do :laugh: Upon compile, it clashes with theCreateWindow
macro giving me an error:warning C4003: not enough actual parameters for macro 'CreateWindowW' error C2059: syntax error : 'constant'
Would somebody be kind enough to help me out with this as I really really want to keep that function name.Actually the problem is due to circular macro. i.e.
CreateWindow
expands toCreateWindowW
(on UNICODE). Again, isCreateWindowW
is macro, which is defined as,#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)It expects 11 params, against 2 provided. Hence , there is macro mismatch, and error. You can use ,
#ifdef CreateWindow
#undef CreateWindow
#endifBut, this will prevent you from using this macro elsewhere in application.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
Not really a big problem since I could just rename my function, but nontheless, I would like to know how to correctly deal with this. I have a class with a member function:
virtual HWND CreateWindow( DWORD dwStyle, HWND hWndParent );
No prizes for guessing what the derived class should do :laugh: Upon compile, it clashes with theCreateWindow
macro giving me an error:warning C4003: not enough actual parameters for macro 'CreateWindowW' error C2059: syntax error : 'constant'
Would somebody be kind enough to help me out with this as I really really want to keep that function name.WalderMort wrote:
I really really want to keep that function name.
Short answer: you can't. Because "CreateWindow" is a macro, the replacement of "CreateWindow" with "CreateWindowA/W" is done by the preprocessor, without regard to scopes or namespaces. This is why, for example, the MFC and ATL methods are called
Create()
and notCreateWindow()
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ