Why wont this work

Started by
25 comments, last by kapru 20 years, 4 months ago
quote:Original post by stro
Shouldn't you have

d3dpp.hDeviceWindow = Apphwnd;

?


If d3dpp.hDeviceWindow is NULL, then it will use the focus window passed in the CreateDevice call. So it's not strictly necessary. In this case it wouldn't help anyway. The DirectX debug output clearly states that neither of these had a value. The problem is definitely prior the the InitDirect3D function.


[edited by - Dave Hunt on December 16, 2003 11:38:36 AM]
Advertisement
Very true.

I noticed that he doesn''t check if Apphwnd is valid.
It seems very likely to me that it isn''t.

I used to have this problem whenever I only had a return in my message handler - CreateWindow would fail with an error code of 1 : "File not found" - very confusing.

Check all the API calls and use MessageBox to display results, or a logger if you have one.

quote:Original post by Dave Hunt
You''re not checking the return value of CreateWindow(). It is possible that the CreateWindow() call failed and you''re getting NULL for Apphwnd. Given that CreateDevice() is complaining about your window handle, I''d bet that that is the case.

Are ApplicationName and "APP" the same value? If not, that would explain why your window creation failed.

Also, you''re not checking the return value of RegisterClassEx(). If that fails, then your window creation will fail, as well.

Always check return value from API calls. That can save you a lot of headaches.



You are a fukcen legend ApplicationName wasnt given a value and "APP" should be ApplicationName

I have no idea what the fuck i was doing there

cheers for all the help guys
Im getting pritty good with directX but i sux at window specific stuff something im gonna have to learn when i start uni next year
Ok so i got that working so now i went back to fix the original programme and its not working abain and its giving the same error

framework.h
#ifndef _FRAMEWORK_ #define _FRAMEWORK_#include <d3d8.h>#include <d3dx8.h>#include <mmsystem.h>#include <stdio.h>#include <tchar.h>#include <D3DUtil.h>#include <DXUtil.h>#include <dinput.h>#define DIRECTINPUT_VERSION 0x0800#define VEC D3DXVECTOR3#define WINDOWED 1#define FULLSCREEN 0INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT );LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );class CFrameWorkApplication{protected:	int iAppWidth;	int iAppHeight;	int iAppBpp;	bool bWindowed;	int bActive;	int bReady;	int bHasFocus;	HWND Apphwnd;	char *ApplicationName;	LPDIRECT3D8             d3d;	LPDIRECT3DDEVICE8       d3ddevice;	LPDIRECT3DSURFACE8		backbuffer;	LPDIRECT3DSURFACE8		zbuffer;	HRESULT SetDisplayMode();			//Setup up direct 3D	HRESULT ReleaseDisplay();	HRESULT ResetDisplay();	HRESULT ToggleFullScreen();public:	~CFrameWorkApplication();	//Desturctor    CFrameWorkApplication();	//Consturctor	RunApplication();	ShutDownApplication();	SetUpApplication(int width,int height,int bpp,bool screenmode,char *name);	LRESULT FrameWorkMsgProc( HWND hWnd, UINT uMsg, WPARAM wParam,LPARAM lParam );};#endif


framework.cpp
#include "framework.h"static CFrameWorkApplication* pThisApp = NULL;/////////////////////Message handler/////////////////////LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){	return pThisApp->FrameWorkMsgProc(hWnd,msg,wParam,lParam);}////////////////////////Class Constructor	////////////////////////CFrameWorkApplication::CFrameWorkApplication(){    pThisApp = this;	///////////////////	//Setup the class//	///////////////////	//Spec App	bWindowed=false;	bActive=false;	bReady=false;	bHasFocus=false;	iAppWidth=NULL;	iAppHeight=NULL;	iAppBpp=NULL;	Apphwnd=NULL;	ApplicationName=NULL;	d3d=NULL;	d3ddevice=NULL;	backbuffer=NULL;	zbuffer=NULL;}//////////////////////Class Destructor//////////////////////CFrameWorkApplication::~CFrameWorkApplication(){}/////////////////////////////////////////////////This function Creates the Direct 3d Objects/////////////////////////////////////////////////HRESULT CFrameWorkApplication::SetDisplayMode(){	// Create the D3D object.	d3d=Direct3DCreate8(D3D_SDK_VERSION);	if(d3d==NULL)	{		MessageBox(Apphwnd,"Can not creat Direct 3D interface","ERROR",MB_OK);		return E_FAIL;	}	D3DDISPLAYMODE d3ddm;	if(FAILED(d3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )	{		MessageBox(Apphwnd,"Can not get display mode","ERROR",MB_OK);		return E_FAIL;	}	D3DPRESENT_PARAMETERS d3dpp; 	ZeroMemory( &d3dpp, sizeof(d3dpp) );//	if(!bWindowed)//	{		d3dpp.Windowed = false;		d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;		d3dpp.FullScreen_PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;		d3dpp.BackBufferFormat = d3ddm.Format;		d3dpp.EnableAutoDepthStencil = TRUE;		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;		d3dpp.BackBufferWidth=800;//iAppWidth;		d3dpp.BackBufferHeight=600;//iAppHeight;/*	}	else	{		d3dpp.Windowed = true;		d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;		d3dpp.BackBufferFormat = d3ddm.Format;		d3dpp.EnableAutoDepthStencil = TRUE;		//if(iAppBpp==16)		//{			d3dpp.AutoDepthStencilFormat = D3DFMT_D16;		//}		d3dpp.BackBufferWidth=iAppWidth;		d3dpp.BackBufferHeight=iAppHeight;	}*/	HRESULT hr = d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Apphwnd,			            		 D3DCREATE_HARDWARE_VERTEXPROCESSING,								 &d3dpp, &d3ddevice );	if(FAILED(hr))	{		MessageBox(Apphwnd,"Failed to Create a Direct 3D Device","ERROR",MB_OK);		return E_FAIL;	}	d3ddevice->GetRenderTarget(&backbuffer);	d3ddevice->GetDepthStencilSurface(&zbuffer);	return S_OK;}//////////////////////////////////////////////////This function Releases the direct 3d Objects//////////////////////////////////////////////////HRESULT CFrameWorkApplication::ReleaseDisplay(){	return S_OK;}////////////////////////////////////////////////This function Resets the direct 3d object	////when the windows has regained focus of	////switched mode								////////////////////////////////////////////////HRESULT CFrameWorkApplication::ResetDisplay(){	return S_OK;}////////////////////////////////////////////////This function switches between full screen////and windowed mode							////////////////////////////////////////////////HRESULT CFrameWorkApplication::ToggleFullScreen(){	return S_OK;}////////////////////////////////////////////////////This function starts the framework application////////////////////////////////////////////////////CFrameWorkApplication::RunApplication(){	//First we must call the init function//	if(FAILED(InitApp())) goto ShutDown;	//Set the application to active	bActive=true;	WNDCLASSEX wc={sizeof(WNDCLASSEX), CS_CLASSDC,MsgProc, 0L, 0L,					GetModuleHandle(NULL), NULL, NULL, (HBRUSH)GetStockObject(BLACK_BRUSH),					NULL,ApplicationName, NULL };	RegisterClassEx( &wc );	// Create the application's window	Apphwnd = CreateWindow( ApplicationName,ApplicationName,				            WS_EX_TOPMOST, 50, 50, iAppWidth+8, iAppHeight+34,					        GetDesktopWindow(), NULL, wc.hInstance, NULL);	if(!Apphwnd)	{	//	MessageBox(Apphwnd,"Failed to create the Window","ERROR",MB_OK);	//	goto ShutDown;	}	// Show the window	ShowWindow( Apphwnd, SW_SHOWDEFAULT );	UpdateWindow( Apphwnd );	if(FAILED(SetDisplayMode())) goto ShutDown;	bReady=true;	//Now lets get the Application loop running	MSG msg;	ZeroMemory( &msg, sizeof(msg) );	while(msg.message!=WM_QUIT )	{		if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )		{			TranslateMessage( &msg );			DispatchMessage( &msg );		}		else if(bHasFocus && bActive)		{		}	}ShutDown:	//If we get here then the app is closing	ShutDownApplication();	UnregisterClass("ApplicationName", wc.hInstance );}///////////////////////////////////////////////////////This function shutsdown the framework application///////////////////////////////////////////////////////CFrameWorkApplication::ShutDownApplication(){}//////////////////////////////////////////////////////This function is call directly after you declair////the framework because is sets the display params//////////////////////////////////////////////////////CFrameWorkApplication::SetUpApplication(int width,int height,int bpp,bool screenmode,char *name){	iAppWidth=width;	iAppHeight=height;	iAppBpp=bpp;	bWindowed=screenmode;	ApplicationName = name;}/////////////////////////////////////////////The message handler for the application/////////////////////////////////////////////LRESULT CFrameWorkApplication::FrameWorkMsgProc( HWND hWnd, UINT uMsg, WPARAM wParam,LPARAM lParam ){	switch( uMsg )	{		case WM_DESTROY:		PostQuitMessage( 0 );		return 0;		break;	}	return DefWindowProc( Apphwnd, uMsg, wParam, lParam );}


main.cpp
#include "framework.h"INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT ){	CFrameWorkApplication App;	App.SetUpApplication(800,600,16,FULLSCREEN,"TestApp");	App.RunApplication();	//The app has closed so good buy	return 0;}




[edited by - kapru on December 16, 2003 8:19:29 PM]
Well, you''ve got your error checking around the win32 stuff commented out. If you are getting the exact same error you were getting before, then your window creation is failing. If you uncomment the error checking, does your message box display?

If window creation is failing, you can call GetLastError() to find out what the cause of the error was.

I can only repeat what I said before - "Always check return value from API calls. That can save you a lot of headaches."
I know that the windows isnt being created, i have no idea why the creation of the window is failing

i thought maybe its because hwnd dosnt like to be part of a class but that just a stupid thought
You''ve passed an extended window style (WS_EX_TOPMOST) to the non-extended CreateWindow function.

For windowed mode, you should use WS_OVERLAPPEDWINDOW (assuming you want the user to be able to resize the window). For fullscreen mode, you should use WS_POPUP | WS_VISIBLE.

GetLastError() would have told you why the creation failed. It would have returned ERROR_INVALID_WINDOW_STYLE. You can use GetLastError() in conjunction with FormatMessage() to get an error message string describing the error in text.

This topic is closed to new replies.

Advertisement