🔒 Locked
using WndProc as a function parameter ?
Advertisement
Original Post
hi there..
i''m doing a little wraper so that i dont have to type WNDCLASS and define it all.. anyways.. when it comes to the wc.lpfnWndProc , i''m totally lost.. i checked msn and i tried to use WNDPROC WndProc as one of my function param but the system just crashes. So can someone help me out here ? thx in advance
this may not be what you are lookin for but anyways there is an article called Creating a Win32 Window Wrapper Class rith here on game dev 
( I made the asumption that you are using C++ and want to make a wrapper class )
/Please excuse my bad spelling - My native language is binary not english
|Visit me
\Take my advice - I don''''t use it...
( I made the asumption that you are using C++ and want to make a wrapper class )
/Please excuse my bad spelling - My native language is binary not english
|Visit me
\Take my advice - I don''''t use it...
quote:
Original post by DerekSaw
Make sure the calling convention is correct... and post some code.![]()
sure here is it
bool InsiDer::idCreateWindow (char *Title,char *Class,int Width,int Height,unsigned int Style, HINSTANCE Hinstance,HWND Hwnd,WNDPROC WndProc)
{
WNDCLASS Wc;
Wc.cbClsExtra = 0;
Wc.cbWndExtra = 0;
Wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
Wc.hCursor = LoadCursor (NULL,IDC_ARROW);
Wc.hIcon = LoadIcon (NULL,IDI_APPLICATION);
Wc.hInstance = Hinstance;
Wc.lpfnWndProc = WndProc; // THIS IS WHAT IS NOT RIGHT ! :D
Wc.lpszClassName = Class;
Wc.lpszMenuName = NULL;
Wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
if (!RegisterClass (&Wc))
{
MessageBox (NULL,"Window class registration failed !","InsiDer",MB_OK|MB_ICONEXCLAMATION);
return false;
}
Hwnd = CreateWindow (Class,Title,Style,CW_USEDEFAULT,CW_USEDEFAULT,Width,Height,NULL,NULL,Hinstance,NULL);
return true;
}
There seems to be nothing wrong with that code...
Where is the function you are trying to pass as wndproc ? ( I mean is it also in the 'InsiDer' class or what? )
It *migth* help if you posted the line where you call the idCreateWindow methode. ( I suspect that you forgot to cast the function pointer to (WNDPROC) )
/Please excuse my bad spelling - My native language is binary not english
|Visit me
\Take my advice - I don''t use it...
[edit]
As Evil bill correctly said in C++ it's called memberfunctions and not methodes..
( I don't this i'll ever learn that
)
[/edit]
[edited by - guppy on January 6, 2003 9:34:33 PM]
Where is the function you are trying to pass as wndproc ? ( I mean is it also in the 'InsiDer' class or what? )
It *migth* help if you posted the line where you call the idCreateWindow methode. ( I suspect that you forgot to cast the function pointer to (WNDPROC) )
/Please excuse my bad spelling - My native language is binary not english
|Visit me
\Take my advice - I don''t use it...
[edit]
As Evil bill correctly said in C++ it's called memberfunctions and not methodes..
( I don't this i'll ever learn that
[/edit]
[edited by - guppy on January 6, 2003 9:34:33 PM]
quote:
Original post by Evil Bill
WndProc() Isn't a member function of InsiDer is it?
And you shouldn't cast function pointers unless you know what you're doing. If it is a member function, check out that Window Wrapper Class that Guppy posted, you'll see how to fix it.![]()
this is what it is CreateWindow is intended to do...
#include <windows.h>
#include "InsiDer.h"
LRESULT CALLBACK WndProc ( ...);
int WINAPI WinMain ( ... )
{
MSG Msg;
InsiDer *Wrapper;
Wrapper->idCreateWindow ( ... );
ShowWindow ( ...);
//Message Looping
....
return Msg.wParam;
}
LRESULT CALLBACK WndProc ( ...)
{
...
}
and u can see i just want to pass the WndProc to idCreate so it can set on the Wc.lpfnWndProc "WNDCLASS" THIS Procedure .. got it ? just like i would do it if i didn't have the function ..
and by the way. idCreateWindow is a static if that matters 0_o
[edited by - Metal Typhoon on January 6, 2003 10:02:01 PM]
Actualy id like to see what is inside the dot''s here:
Wrapper->idCreateWindow ( ... );
---
ps. also I don''t think you''ve initialized wrapper...
all though idCreateWindow is static the *could* be a problem if the members variables it''s accessing is not.. (as the code looks like a fast made up example I don''t think that it aplies - but still..)
Wrapper->idCreateWindow ( ... );
---
ps. also I don''t think you''ve initialized wrapper...
all though idCreateWindow is static the *could* be a problem if the members variables it''s accessing is not.. (as the code looks like a fast made up example I don''t think that it aplies - but still..)
quote:
Original post by guppy
Actualy id like to see what is inside the dot''s here:
Wrapper->idCreateWindow ( ... );
---
ps. also I don''t think you''ve initialized wrapper...
all though idCreateWindow is static the *could* be a problem if the members variables it''s accessing is not.. (as the code looks like a fast made up example I don''t think that it aplies - but still..)
HWND Hwnd // this is a global;
("Testing window","Test",800,600,WS_CAPTION,Hinstance,Hwnd,WndProc);
quote:
Original post by Evil Bill
Where does it crash?![]()
win xp ... it restarts the pc automatically :D
quote:
Original post by Metal Typhoon
HWND Hwnd // this is a global;
("Testing window","Test",800,600,WS_CAPTION,Hinstance,Hwnd,WndProc);
Try inserting (WNDPROC) before WndProc in that statement like so:
("Testing window","Test",800,600,WS_CAPTION,Hinstance,Hwnd,(WNDPROC)WndProc);
dunno why but it seems necesary to make that cast. If that does not solve you problem im got no clue as to what is goin on...
quote:
win xp ... it restarts the pc automatically :D
Eek! Thats a bad sign :s
Can you not trace into it and see where the problem is?
My guess is that your arguments are wrong or something. That would cause the OS to call your WndProc with the wrong parameters, mess up the stack and could well bring down the OS. Anything else should result in an access violation or something.
ok since the all the source is small i''ll put them here .. nothing that u guys dont know how to do 
this is a Dynamic - link library project
InsiDer.h
idWrapper.cpp
and this is all... i''ve done the other .cpp file to define other functions.. they all work fine cuz i tested them with another app enabling ogl and such..
this is a Dynamic - link library project
InsiDer.h
#ifndef _InsiDer_H
#define _InsiDer_H
#pragma comment (lib,"glu32.lib")
#pragma comment (lib,"opengl32.lib")
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#define DE _declspec (dllexport)
namespace InsiDer_Engine
{
class DE InsiDer
{
public:
/*-------------------------------------------------------------*\
|idCreateWindow - Wraper to an easy window creation |
\*-------------------------------------------------------------*/
static bool idCreateWindow (char *Title,char *Class,int Width,int Height,unsigned int Style,
HINSTANCE Hinstance,HWND Hwnd,WNDPROC WndProc);
/*-------------------------------------------------------------*\
|idEnableRenderer - Enables Opengl to a window |
|idDisableRenderer - Disables Opengl to a window |
|idChangeResolution - Changes screen resolution |
|idResizeSceneModel - Resize a scene using perspective |
|idResizeSceneOrtho - Resize a scene using orthographic |
\*-------------------------------------------------------------*/
static bool idEnableRenderer (HWND &Hwnd,HDC &Hdc,HGLRC &Hrc,int Colors,int Depth);
static bool idDisableRenderer (HWND Hwnd,HDC Hdc,HGLRC Hrc);
static bool idChangeResolution (int Width,int Height,int Depth);
static void idResizeSceneModel (int Width,int Height,float Start,float End,bool Cinema);
static void idResizeSceneOrtho (int Left,int Right,int Top,int Bottom,bool Cinema);
};
}
#endif
idWrapper.cpp
include "InsiDer.h"
namespace InsiDer_Engine
{
bool InsiDer::idCreateWindow (char *Title,char *Class,int Width,int Height,unsigned int Style,
HINSTANCE Hinstance,HWND Hwnd,WNDPROC WndProc)
{
WNDCLASS Wc;
Wc.cbClsExtra = 0;
Wc.cbWndExtra = 0;
Wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
Wc.hCursor = LoadCursor (NULL,IDC_ARROW);
Wc.hIcon = LoadIcon (NULL,IDI_APPLICATION);
Wc.hInstance = Hinstance;
Wc.lpfnWndProc = WndProc;
Wc.lpszClassName = Class;
Wc.lpszMenuName = NULL;
Wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
if (!RegisterClass (&Wc))
{
MessageBox (NULL,"Window class registration failed !","InsiDer",MB_OK|MB_ICONEXCLAMATION);
return false;
}
Hwnd = CreateWindow (Class,Title,Style,CW_USEDEFAULT,CW_USEDEFAULT,
Width,Height,NULL,NULL,Hinstance,NULL);
return true;
}
}
and this is all... i''ve done the other .cpp file to define other functions.. they all work fine cuz i tested them with another app enabling ogl and such..
Ahhhh Its a DLL....
Make sure the hInstance in the WNDCLASS structure is the hInstance of the DLL, not the Application! The hInstance determines what object the WndProc is in.
Also, your HWND isn''t being returned, since you''re passing it by reference. Consider either returning the HWND (NULL for error), or taking a HWND reference or pointer.
HTH
Make sure the hInstance in the WNDCLASS structure is the hInstance of the DLL, not the Application! The hInstance determines what object the WndProc is in.
Also, your HWND isn''t being returned, since you''re passing it by reference. Consider either returning the HWND (NULL for error), or taking a HWND reference or pointer.
HTH
quote:
Original post by Evil Bill
Ahhhh Its a DLL....
Make sure the hInstance in the WNDCLASS structure is the hInstance of the DLL, not the Application! The hInstance determines what object the WndProc is in.
Also, your HWND isn't being returned, since you're passing it by reference. Consider either returning the HWND (NULL for error), or taking a HWND reference or pointer.
HTH![]()
oh CRAP ! j00 forgot about Hwnd being a reference
i jsut tried just change the HWND to a reference and it worked :D now why would it need to be the dll hinstance ?
[edited by - Metal Typhoon on January 6, 2003 10:43:11 PM]
guys i have a question to ask.. the way you see my coding above you must be saying "what a nub look at him and his little engine is development" is this the writ way to start one ? or if not can you guys give me good programming tips for engines ?
i want to build my engine all in dll files.. so what would be the break out by category ?
render
file loaders
console
physics
and what else ? thx alot
i want to build my engine all in dll files.. so what would be the break out by category ?
render
file loaders
console
physics
and what else ? thx alot
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement