Help with window class and some error

Started by
7 comments, last by kingpinzs 18 years, 5 months ago
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

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;



[Edited by - kingpinzs on November 23, 2005 2:51:41 PM]
Advertisement
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?
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.:
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
How is MessageLoop declared?

Enigma
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){    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
Thanks for every once help it helped to get the code to work. So just incase any one runs into this problem the code in the book
real-time strategy game programming using dx 6 there is about 5 modifications before it works one is what you guys fixed for me.

This topic is closed to new replies.

Advertisement