Skip to main content
gamedev.net
🔒 Locked

Wrapper Problems with window instance

Started by CloudNine 5 replies 650+ views
Original Post
CloudNine
CloudNine
I''m currently working on a wrapper for DirectX and Win32, but have got stuck on the handle to the instance. The WinMain and the window setup are in two different files. Here''s the different source files: CApplication.cpp (The InitWindow function)
  
bool CGOApp::goInitWindow()
{
WNDCLASSEX wc;

wc.cbSize=sizeof(WNDCLASSEX);
wc.style=CS_OWNDC;
wc.lpfnWndProc=WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=goGetInstance();
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=NULL;
wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=WINDOWTITLE;
wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);

RegisterClassEx(&wc);

hWnd=CreateWindowEx(WS_EX_CONTROLPARENT,WINDOWTITLE,WINDOWTITLE,
                    WS_OVERLAPPED,WINWIDTH,WINHEIGHT,0,0,
                    wc.hInstance,0);

return true;
}
  
Main.cpp (Containing the WinMain function)
  
#include "main.h"

CGOApp cApp;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmd, int nShow)
{
MSG messages;

while (cApp.goWindowAlive())
{
 if(GetMessage(&messages,NULL,0,0))
 {
  TranslateMessage(&messages);
  DispatchMessage(&messages);
 }
}
return false;
}
  
It comes up with errrors in the CreateWindowEx function call, such as this: type HWND__'' is not a base type for type HINSTANCE__'' Thanks in advance
Spacecat
Spacecat
Well, you could have a look at my own silly little wrapper for MechaEngine. http://www.geocities.com/francois_dion/CodePage.html

You probably won''t like it because I''ve put it into a namespace instead of an object. But have a look at the APPLICATION library anyway for a few ideas. (I suspect your goGetInstance() function isn''t returning what it should, BTW, or that wc.hInstance hasn''t the right type.)

Of course I''ve meant mine strictly as a video game core not too dependent of Win32 and DirectX (In an exploratory manner).
=^.^= Leaders and teachers should remember: It is best to offer others what they Need, not what they Want.
Dave Hunt
Dave Hunt
You could GetModuleHandle() to get the instance of the current application. Then you don''t need access to the hInstance parameter passed to WinMain().

The HMODULE value returned can be used whereever an HINSTANCE is called for.
CloudNine
CloudNine
It still returns the same error, which really puzzles me, even after typingcasting.
Dave Hunt
Dave Hunt
Dude, CreateWindowEx() doesn't take 10 parameters. It takes 12. Here is the prototype:

HWND CreateWindowEx(
DWORD dwExStyle,
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);

(You're missing the x,y parameters.)

Did you not get an error saying "CreateWindowEx - function does not take 10 parameters" or similar?


[edited by - Dave Hunt on May 8, 2003 11:05:06 AM]
CloudNine
CloudNine
Damn, it didn''t mention any error like that. Thanks though

Topic Locked

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

Sign in to reply to this topic.