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. Class+WNDPROC

Class+WNDPROC

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 4 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.
  • S Offline
    S Offline
    shaderx
    wrote on last edited by
    #1

    Hi i have a class that makes a custom window,and at the WNDCLASS structure at wc.lpfnWndProc=(WNDPROC)&CustomWindow::WndProc; i get the error: error C2440: 'type cast' : cannot convert from 'LRESULT (__stdcall CustomWindow::*) (HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC' There is no context in which this conversion is possible worked before in non class app as wc.lpfnWndProc=WndProc; if someone could point out the problem or share a solution, it would be very apriciated.

    M 1 Reply Last reply
    0
    • S shaderx

      Hi i have a class that makes a custom window,and at the WNDCLASS structure at wc.lpfnWndProc=(WNDPROC)&CustomWindow::WndProc; i get the error: error C2440: 'type cast' : cannot convert from 'LRESULT (__stdcall CustomWindow::*) (HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC' There is no context in which this conversion is possible worked before in non class app as wc.lpfnWndProc=WndProc; if someone could point out the problem or share a solution, it would be very apriciated.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      To use a member function (method) as a callback like this, the method needs to be declared static. That's because the OS knows nothing of your C++ object so it can't pass the implicit "this" pointer that gets passed to non-static class methods. Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      S 1 Reply Last reply
      0
      • M Mark Salsbery

        To use a member function (method) as a callback like this, the method needs to be declared static. That's because the OS knows nothing of your C++ object so it can't pass the implicit "this" pointer that gets passed to non-static class methods. Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        S Offline
        S Offline
        shaderx
        wrote on last edited by
        #3

        Could you be more specific because im a noob :D should i put static in front of my method declaration ? Thanks for putting up with me in advance :P

        M T 2 Replies Last reply
        0
        • S shaderx

          Could you be more specific because im a noob :D should i put static in front of my method declaration ? Thanks for putting up with me in advance :P

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

          See 6.1 Why can't I use a member function as a callback?[^] [33.2] How do I pass a pointer-to-member-function to a signal handler, X event callback, system call that starts a thread/task, etc?[^]

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.

          1 Reply Last reply
          0
          • S shaderx

            Could you be more specific because im a noob :D should i put static in front of my method declaration ? Thanks for putting up with me in advance :P

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

            shaderx wrote:

            should i put static in front of my method declaration ?

            offcourse ! :cool:

            "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
            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