Skip to main content
GameDev.net gamedev.net
🔒 Locked

assigning WinProc problem.

Started by Jason2Jason Jan 24, 2003 at 6:54 PM 6 replies 200+ views
Original Post
Jason2Jason
Jason2Jason
Hey ppl. I got a unusual compiler problem today, saying that it cant convert the WinProc function to a type. Heres the compiler error:
error C2440: '=' : cannot convert from 'long (__stdcall CWindow::*)(struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(struct 
HWND__ *,unsigned int,unsigned int,long)'
        There is no context in which this conversion is possible
  
Here is there winproc definition and the part where i assign it:
    
LRESULT CALLBACK WndProc(	HWND	hWnd,					// Handle For This Window

							UINT	uMsg,								// Message For This Window

							WPARAM	wParam,								// Additional Message Information

							LPARAM	lParam)								// Additional Message Information



	//Registering the Window Class

    //WndClass.cbSize        = sizeof(WNDCLASSEX);

    //WndClass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;

    WndClass.lpfnWndProc   = WndProc;
    //WndClass.cbClsExtra    = 0;

    //WndClass.cbWndExtra    = 0;

    //WndClass.hInstance     = *hInstance;

    //WndClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);

    //WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);

    //WndClass.hbrBackground = NULL;

    //WndClass.lpszMenuName  = NULL;

    //WndClass.lpszClassName = ClassName;

    //WndClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);


//Comments above are to show you the ones i'm not talking about to point out the line that i am.


    
Extra info: I tried to use a typecaste "(WinProc)" as i saw in other apps, but this didnt work. Also the winproc function and the setup code is part of a window C++ class. Any idea how to solve this problem? -J [edited by - jason2jason on January 24, 2003 8:02:38 PM]
Jason2Jason
Jason2Jason
No, it made another error saying: 1 unresolved externals.

hmm,

-J
boohillie
boohillie
Whoops I wrote the definition wrong.
try this:
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

I had WPARAM and LPARAM switched. My bad.

I tried it just now and it works, here''s my code.


  
#include <windows.h>

class CWindow
{
public:
CWindow(char*, int, int);

private:
WNDCLASSEX wc;
HWND hWnd;
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
};

CWindow::CWindow(char* title, int width, int height)
{
HINSTANCE hInstance = GetModuleHandle(NULL);

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = TESTWINDOW;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

RegisterClassEx(&wc);

hWnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
title,
title,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, width, height,
NULL, NULL, hInstance, NULL);

ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);

}

LRESULT CALLBACK CWindow::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}

return 0;
}




INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
CWindow win("Test", 640, 480);

while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}

DerekSaw
DerekSaw
Hopes you know what the static keyword mean.
"after many years of singularity, i'm still searching n the event horizon" o
Jason2Jason
Jason2Jason
First of all, i put the static keyword infront of the existing definition, so if you got the first one wrong, it woulnd''t have mattered.

Secondly, i do know what it means. I wasn''t sure if it could be used for functions or not so i tried anyway. It means that the variable will still exist even if it goes out of scope.

So, are there any other idea of how i could be going wrong?

Thx,

-J
Jason2Jason
Jason2Jason
Well right now i think i''ll only need one CWindow in the game.. i might just creat the winproc out side the class, and pass a pointer from that, to the class.. This would make my class more reusable than it presently is..

Thanks for all the help..

-J

Topic Locked

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

Sign in to reply to this topic.