471,831 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,831 software developers and data experts.

Working on a header file for OpenGL

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:


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
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
1 1646
9,208 Expert Mod 8TB
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. );
In winuser.h you see:
Expand|Select|Wrap|Line Numbers
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. );
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;
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. );
Aug 11 '07 #2

Post your reply

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

Similar topics

15 posts views Thread by oracle411 | last post: by
2 posts views Thread by yanwan | last post: by
10 posts views Thread by Bad_Kid | last post: by
9 posts views Thread by Daniel | last post: by
4 posts views Thread by tobfon | last post: by
9 posts views Thread by Achim Domma | last post: by
2 posts views Thread by urbanedge | last post: by
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.