By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.

Working on a header file for OpenGL

P: 23
It's meant to make making Windows for the API quiker and easier, but one of the problems is that in order to properly create a window with a create window function, needs to know about the Windows Procedure, but I don't know if you can properly pass a windows procedure wihtout parameters to a function in an include file. Lets say I create a Windows Procedure with typical parameters like this:

LRESULT CALLBACK(HWND, UINT, WPARAM, LPARAM);

Then how would I get the function in the include file to know about it? First part of function in include file is as follows (because it's massive, didn't want to overwhelm people). For the sake of concisity, I've only included the part I'm having trouble with, since I know the rest is error free.:

bool CreateGLWindow(char* title, char* Classname, int width, int height, int bits, bool fullscreenflag, HWND hWnd
, HINSTANCE hInstance, HGLRC hRC, HDC hDC)
{
WNDCLASS wc;
wc.lpfnWndProc = (WNDPROC)WndProc;/*"WndProc undeclared! But I can't pass it as a parameter unless I use parameters for the function, but that causes errors. Should I make all parameters for WndProc optional so I don't have to pass anything? That wouldn't work...*/

I need a way to tell the function in the header file that WinProc is the function that I want to use, and a way to pass it as a parameter without passing parameters to it. Can someone help me with this?
Aug 11 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
I'm a little confused by phrases like:
I need a way to tell the function in the header file that ...
becuse there are no functions in a header file. And if there are, you have bigger problems than what you have posted.

First, a WNDPROC is a function pointer to a function like this:
Expand|Select|Wrap|Line Numbers
  1. LRESULT CALLBACK WindowProc(          HWND hwnd,
  2.     UINT uMsg,
  3.     WPARAM wParam,
  4.     LPARAM lParam
  5. );
  6.  
In winuser.h you see:
Expand|Select|Wrap|Line Numbers
  1. typedef LRESULT (CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM);
  2.  
which says that a WNDPROC is a pointer to a function with specific arguments and return type.

For your WndProc function to be used as a WNDPROC is must have this prototype:
Expand|Select|Wrap|Line Numbers
  1. LRESULT CALLBACK WndProc(          HWND hwnd,
  2.     UINT uMsg,
  3.     WPARAM wParam,
  4.     LPARAM lParam
  5. );
  6.  
I assume that it does.

Now this error:
wc.lpfnWndProc = (WNDPROC)WndProc;/*"WndProc undeclared!
tells me that the function prototype for WndProc is not available at the time this case is made. And, by the way, you don't need the cast if your WndProc has the correct prototype,. You should be able to:

Expand|Select|Wrap|Line Numbers
  1. wc.lpfnWndProc = WndProc;
  2.  
Lastly, I would not use the name WndProc for your function. Use something not likely to be confused witrh Windows code. Maybe:

Expand|Select|Wrap|Line Numbers
  1. LRESULT CALLBACK MyGLWindow(          HWND hwnd,
  2.     UINT uMsg,
  3.     WPARAM wParam,
  4.     LPARAM lParam
  5. );
  6.  
Aug 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.