• Advertisement

Archived

This topic is now archived and is closed to further replies.

Wrapper Problems with window instance

This topic is 5374 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
It still returns the same error, which really puzzles me, even after typingcasting.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • Advertisement