   Win32 Wrapper
  I am having a little trouble with a learning experiment of mine to create a small Win32 wrapper.Error:error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'WNDPROC'\visual studio 2008\projects\win32wrapper\win32wrapper\win32baseclass.cpp15And here's the source:MainEntry.cpp#include "Win32BaseClass.h"int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){WindowBase32 Wnd32;if (!Wnd32.InitWindow(hInstance, 640, 480)){return 1;}//Message loopMSG msg = {0};while (WM_QUIT != msg.message){while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE){TranslateMessage(&msg);DispatchMessage(&msg);}//Extra logic}return (int)msg.wParam;}Win32BaseClass.h#include <windows.h>class WindowBase32{private://PRIVATE//public://PUBLIC//HINSTANCE hInst;HWND wndHandle;bool InitWindow(HINSTANCE hInstance, int wndWidth, int wndHeight);LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);};Win32BaseClass.cpp#include "Win32BaseClass.h"bool WindowBase32::InitWindow(HINSTANCE hInstance, int wndWidth, int wndHeight){WNDCLASSEX wcex;//Fill it inwcex.cbSize = sizeof(WNDCLASSEX);wcex.style = CS_HREDRAW | CS_VREDRAW;wcex.lpfnWndProc = (WNDPROC)WndProc;wcex.cbClsExtra = 0;wcex.cbWndExtra = 0;wcex.hInstance = hInstance;wcex.hIcon = 0;wcex.hCursor = LoadCursor(NULL, IDC_ARROW);wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);wcex.lpszMenuName = NULL;wcex.lpszClassName = "DragonEngine";wcex.hIconSm = 0;if (!RegisterClassEx(&wcex)){::MessageBox(NULL, TEXT("Window failed registration!"), "Error!", MB_ICONERROR | MB_OK);return false;}RECT rect = { 0, 0, wndWidth, wndHeight };AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false);//Create Windowthis->wndHandle = CreateWindow("DragonEngine", "Code: E.N.D.", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, NULL);if (!(this->wndHandle)){return false;}ShowWindow((this->wndHandle), SW_SHOW);UpdateWindow((this->wndHandle));return true;}LRESULT CALLBACK WindowBase32::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){//Check for messagesswitch (message){case WM_KEYDOWN:{switch (wParam){//Escape keycase VK_ESCAPE:{PostQuitMessage(0);break;}}break;}case WM_DESTROY:{PostQuitMessage(0);break;}break;}return DefWindowProc(hWnd, message, wParam, lParam);}
  You will need to make WndProc a static member of the class, as it requires a 'this' to be called. To get a 'this' pointer, you could keep a static map using HWND as the key, and WindowBase32* as the value. A quick example:class WindowBase32{private://PRIVATE//public://PUBLIC//HINSTANCE hInst;HWND wndHandle;bool InitWindow(HINSTANCE hInstance, int wndWidth, int wndHeight);LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);static LRESULT CALLBACK wrapWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);typedef std::map< HWND, WindowBase32* > TThisMap;static TThisMap ThisMap;};LRESULT CALLBACK WindowBase32::wrapWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){TThisMap::iterator Iter = ThisMap.find( hWnd );if( Iter != ThisMap.end() ){return (*Iter).second.WndProc( hWnd, message, wParam, lParam );}return 0;};  I'm a beginner too but I'll try to help :p Is this line 15?wcex.lpfnWndProc = (WNDPROC)WndProc;If it is, than try to remove (WNDPROC) and try not to overload WndProc and WinMain, so something like:wcex.lpfnWndProc = MainWndProc;I may be wrong, I'm just beginning.EDIT:Oops, I didn't notice you got a reply already.   ;  Just need to call your windows message pump like this inside of your classstatic LRESULT CALLBACK MyWindowProc(HWND hWndMain,UINT uMsg,WPARAM wParam,LPARAM lParam);   ;  1.  Pointers to member functions are different from pointers to functions.2.  Don't cast function pointers3.  Related to #1...as people have already pointed out you can't (directly) use a member function as a WndProc for window class, you instead have to use a free function or a static member function.  To get our messages to a member function, there are 3 techniques I know of that have been used by various C++ Win32 wrappers:-Stick a pointer to the class instance in GWLP_USERDATA-Stick a pointer to the class instance in Thread Local Storage (this is the approach taken by MFC)-Use a thunk to "fix up" a call to the WndProc so that it has a this pointer (this is the approach taken by ATL)   ;  Ok, I got it to work by making WndProc static.  Thanks for all the help, and I got some great bookmarks now, too.   