Archived

This topic is now archived and is closed to further replies.

Pointer To Function Error

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writting a windows wrapper class and I wanted the class constructor to accept a pointer to the WindowProcedure function. It gives this error: main.cpp:8: invalid conversion from `LRESULT (*)(HWND__*, unsigned int, unsigned int, long int)' to `LRESULT (*)(HWND__*, unsigned int, unsigned int, long int)' main.cpp:8: initializing argument 1 of `CWND::CWND(LRESULT (*)(HWND__*, unsigned int, unsigned int, long int))' Here is the code:
#include <windows.h>

#ifndef CWND_H
#define CWND_H

class CWND {
  protected:
    HWND   m_hwnd; // handle to the window
    HDC    m_hdc;  // handle to the window's device context (acquired at initialization)
    MSG    m_msg;  // windows message
  
  private:  
    
  public: 
    // Class Constructor / Deconstructor
    CWND(LRESULT CALLBACK (*WndProc)(HWND, UINT, WPARAM, LPARAM));
      ~CWND();
};

#endif


// Constructor
CWND::CWND(LRESULT CALLBACK (*WndProc)(HWND, UINT, WPARAM, LPARAM))
{

}

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int main()
{
  // construct the class
  CWND *Window = new CWND(WndProc);
  for(;
  {
  }
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
}
 
[edited by - Premonition on April 20, 2004 7:15:59 PM]

Share this post


Link to post
Share on other sites
Try it with LRESULT (CALLBACK* WndProc)(HWND, UINT, WPARAM, LPARAM);

winuser.h also provides a typedef for this type, called WNDPROC. Might be better to use that


CWND(WNDPROC WndProc);

Share this post


Link to post
Share on other sites