Sign in to follow this  
kingpinzs

Help with window class and some error

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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));
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this