HWND DIRECT_DRAW_MANGER:: CreateMainWindow(int w, int h, char* ClassName, void* MessageLoop, void* hInst, bool FullScreen )
{
WNDCLASS wcx;
FullScreenFlag = FullScreen;
wcx.style= CS_HREDRAW | CS_VREDRAW ;
wcx.lpfnWndProc = /*(long(_stdcall *)(void *, unsigned int, unsigned int, long))*/MessageLoop;//this is were the error is accuring
wcx.cbClsExtra=0;
wcx.cbWndExtra=0;
wcx.hInstance= (HINSTANCE)hInst;
wcx.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wcx.hCursor=LoadCursor(NULL,IDC_ARROW);
wcx.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wcx.lpszMenuName=ClassName;
wcx.lpszClassName=ClassName;
Help with window class and some error
I am trying to compile a windows class from a book I have and these are the error I am getting.
invalid conversion from `void*' to `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)'
error for below code
[Edited by - kingpinzs on November 23, 2005 2:51:41 PM]
wcx.lpfnWndProc is expecting a particular thing and you are passing it the wrong thing. It is expecting a WindowProc function and you are handing it a void pointer. You need to adjust your definition of MessageLoop in your function parameter list so that it follows the correct format for a function pointer. Here is a page that shows how to pass a function pointer.
well I got it to work by doing this
wcx.lpfnWndProc = (WNDPROC)MessageLoop;
but in code
HWND DIRECT_DRAW_MANGER:: CreateMainWindow(int w, int h, char* ClassName, void* MessageLoop, void* hInst, bool FullScreen )
how do I cahnge void* MessageLoop to something else because I am now getting a new error in code
hwnd = DDraw->CreateMainWindow(SCREEN_WIDTH, SCREEN_HEIGHT,"GAME WINDOW",MessageLoop, hInstance, FullScreenFlag);
initializing argument 4 of `HWND__* DIRECT_DRAW_MANGER::CreateMainWindow(int, int, char*, void*, void*, bool)'
So how could I fix this?
wcx.lpfnWndProc = (WNDPROC)MessageLoop;
but in code
HWND DIRECT_DRAW_MANGER:: CreateMainWindow(int w, int h, char* ClassName, void* MessageLoop, void* hInst, bool FullScreen )
how do I cahnge void* MessageLoop to something else because I am now getting a new error in code
hwnd = DDraw->CreateMainWindow(SCREEN_WIDTH, SCREEN_HEIGHT,"GAME WINDOW",MessageLoop, hInstance, FullScreenFlag);
initializing argument 4 of `HWND__* DIRECT_DRAW_MANGER::CreateMainWindow(int, int, char*, void*, void*, bool)'
So how could I fix this?
Did you read the article that acraig linked to (the second one)? Like he said, you need to pass a function pointer, not a void *, i.e.:
Or, using a typedef:
Enigma
HWND DIRECT_DRAW_MANGER:: CreateMainWindow(int w, int h, char* ClassName, LRESULT (*MessageLoop)(HWND, UINT, WPARAM, LPARAM), void* hInst, bool FullScreen )
Or, using a typedef:
typedef LRESULT (*MessageFunction)(HWND, UINT, WPARAM, LPARAM);HWND DIRECT_DRAW_MANGER:: CreateMainWindow(int w, int h, char* ClassName, MessageFunction MessageLoop, void* hInst, bool FullScreen )
Enigma
sorry I think I asked the wrong question because reading the info on the link and falowing your instructions I get error
invalid conversion from `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)' to `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)'
from this call
hwnd = DDraw->CreateMainWindow(SCREEN_WIDTH, SCREEN_HEIGHT,"GAME WINDOW", MessageLoop, hInstance, FullScreenFlag);
i tryed MessageFunction MessageLoop also at this point and it did not work it is set that way in the class and it does not give any errors
I know I am closer now but not sure what to do next
invalid conversion from `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)' to `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)'
from this call
hwnd = DDraw->CreateMainWindow(SCREEN_WIDTH, SCREEN_HEIGHT,"GAME WINDOW", MessageLoop, hInstance, FullScreenFlag);
i tryed MessageFunction MessageLoop also at this point and it did not work it is set that way in the class and it does not give any errors
I know I am closer now but not sure what to do next
in my header it is
LRESULT CALLBACK MessageLoop(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
and in cpp it is
LRESULT CALLBACK MessageLoop(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
and in cpp it is
LRESULT CALLBACK MessageLoop(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){ switch(message) { case WM_ACTIVATEAPP: ActiveApp = wParam; break; case WM_KEYDOWN: { //check for escape key if(wParam==VK_ESCAPE) { DestroyWindow(hwnd); return(0);//handled message } }break; case WM_DESTROY://the window is being destroyed { //tell the application we are quitting PostQuitMessage(0); //handled message, so return 0 return(0); }break; case WM_MOVE: { }break; case WM_MOUSEMOVE: { }break; case WM_PAINT://the window needs repainting { //handled message, so return 0 return(0); }break; } //pass along any other message to default message handler return(DefWindowProc(hwnd,message,wParam,lParam));}
Ah yes, I'd forgotten the calling convention. Change what I posted before to:
... (CALLBACK *MessageLoop)(...)
Enigma
... (CALLBACK *MessageLoop)(...)
Enigma
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement