Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Function name clashing with MACRO

Function name clashing with MACRO

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
11 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Waldermort
    wrote on last edited by
    #1

    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 the CreateWindow 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.

    C T P M 4 Replies Last reply
    0
    • W Waldermort

      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 the CreateWindow 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.

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      #undef CreateWindow what you think about ?

      T V W 3 Replies Last reply
      0
      • C CPallini

        #undef CreateWindow what you think about ?

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • W Waldermort

          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 the CreateWindow 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.

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • T ThatsAlok

            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

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #5

            Why? :confused:

            1 Reply Last reply
            0
            • C CPallini

              #undef CreateWindow what you think about ?

              V Offline
              V Offline
              Viorel
              wrote on last edited by
              #6

              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 other CreateWindow member.

              C 1 Reply Last reply
              0
              • C CPallini

                #undef CreateWindow what you think about ?

                W Offline
                W Offline
                Waldermort
                wrote on last edited by
                #7

                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:

                T 1 Reply Last reply
                0
                • V Viorel

                  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 other CreateWindow member.

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #8

                  Actually the API is still available, though you have to call the proper one (you can also define by yoursef a macro to wrap the standard/unicode issue). :)

                  1 Reply Last reply
                  0
                  • W Waldermort

                    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:

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • W Waldermort

                      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 the CreateWindow 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.

                      P Offline
                      P Offline
                      prasad_som
                      wrote on last edited by
                      #10

                      Actually the problem is due to circular macro. i.e. CreateWindow expands to CreateWindowW (on UNICODE). Again, is CreateWindowW 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
                      #endif

                      But, this will prevent you from using this macro elsewhere in application.

                      Prasad Notifier using ATL | Operator new[],delete[][^]

                      1 Reply Last reply
                      0
                      • W Waldermort

                        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 the CreateWindow 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.

                        M Offline
                        M Offline
                        Michael Dunn
                        wrote on last edited by
                        #11

                        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 not CreateWindow()

                        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups