Skip to main content
gamedev.net
🔒 Locked

Pointer To Function Error

Started by Premonition Apr 20, 2004 at 6:14 PM 2 replies 350+ views
Original Post
Premonition
Premonition
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]
SiCrane
SiCrane
Did you try replacing all the long hand function pointer notations with the WNDPROC typedef?
Jingo
Jingo
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);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.