Archived

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

Why wont this work

This topic is 5113 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

Im trying to create a d3d window and it wont work ive compaired it to other things ive done and i cant see the problem INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT ) { //Set the application to active Active=true; WNDCLASSEX wc={sizeof(WNDCLASSEX), CS_CLASSDC,MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL,ApplicationName, NULL }; RegisterClassEx( &wc ); // Create the application''s window Apphwnd = CreateWindow( "APP","APP", WS_OVERLAPPEDWINDOW, 50, 50, iAppWidth+8, iAppHeight+34, GetDesktopWindow(), NULL, wc.hInstance, NULL); // Show the window ShowWindow( Apphwnd, SW_SHOWDEFAULT ); UpdateWindow( Apphwnd ); //Init every thing Ready=true; if(FAILED(InitDirect3D())) { goto error; } 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(HasFocus && Active) { } } error: //If we get here then the app is ending //run shut down stuff here ReleaseDirect3D(); DestroyWindow( Apphwnd ); UnregisterClass(ApplicationName, wc.hInstance ); return 0; } HRESULT InitDirect3D() { // Create the D3D object. if(NULL==(d3d=Direct3DCreate8(D3D_SDK_VERSION))) { 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(!Windowed) { 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=iAppWidth; d3dpp.BackBufferHeight=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; } if(FAILED(d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Apphwnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp, &d3ddevice ))) { MessageBox(Apphwnd,"Failed to Create a Device","ERROR",MB_OK); return E_FAIL; } d3ddevice->GetRenderTarget(&backbuffer); d3ddevice->GetDepthStencilSurface(&zbuffer); return S_OK; } when it runs im getting the Failed to Create a Device error message any help would be apriciated

Share this post


Link to post
Share on other sites
Check the parameters you''re passing to CreateDevice() for validity. More specifically, make sure that the window handle is valid when calling the function. If it is and the call still fails, try D3DCREATE_SOFTWARE_VERTEXPROCESSING as the create flag.

What kind of gfx card are you using?

Share this post


Link to post
Share on other sites
Here are a few things to try.

First of all, in full screen mode, you need

d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP; d3dpp.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT;
d3dpp.BackBufferCount=1;

Secondly, a lot of times the windowed mode is not what you want for the backBufferFormat try d3dpp.BackBufferFormat =D3DFMT_A8R8G8B8; or D3DFMT_X8R8G8B8;


and lastly set your AutoDepthStencilFormat=D3DFMT_D24S8;


Try these things, and if the error is still there, it may be in the initialization of your window itself.

Share this post


Link to post
Share on other sites
Here is the debug output
irect3D8: :====> EXIT: DLLMAIN(00aec640): Process Attach: 0000096c
Direct3D8: (INFO) :Direct3D8 Debug Runtime selected.
Loaded ''C:\WINDOWS\system32\uxtheme.dll'', no matching symbolic information found.
Direct3D8: (ERROR) :Neither hDeviceWindow nor Focus window specified. CreateDevice Failed.
Direct3D8: :====> ENTER: DLLMAIN(00aec640): Process Detach 0000096c, tid=00000eb0
Direct3D8: (INFO) :MemFini!
Direct3D8: :====> EXIT: DLLMAIN(00aec640): Process Detach 0000096c
The thread 0xEB0 has exited with code 0 (0x0).
The program ''C:\Engine Dev\Frame Work\Debug\Frame Work.exe'' has exited with code 0 (0x0).

The problem is here
Direct3D8: (ERROR) :Neither hDeviceWindow nor Focus window specified. CreateDevice Failed.

I can''t see why this is happening

Share this post


Link to post
Share on other sites
Namethatnobodyelsetook (man, that''s so hard to write!) already answered, but I just wanted to stress on something. Always look for "Direct3D(ERROR)" messages, they''ll tell you *exactly* what''s wrong (most of the time).

You got the message:
"Direct3D8: (ERROR) :Neither hDeviceWindow nor Focus window specified. CreateDevice Failed."
Which explains it all.

Use the debug runtime, people. Please

Muhammad Haggag

Share this post


Link to post
Share on other sites
Take a step back for a moment. Your problem is not with Direct3D but with you main window itself. Remove or comment the call to InitDirect3D() and make sure a window appears on screen. With that hurdle cleared, try uncommenting InitDirect3D() .

-----------------------------
kevin@mayday-anime.com
http://www.mayday-anime.com

Share this post


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

Share this post


Link to post
Share on other sites
Maybe it''s just me but I don''t think your WNDCLASSEX is complete.

ANother thing I found strange right off the bat, but thought I was loony, is that you are using a WNDCLASSEX but are not calling createWindowEx.

I dunno, those are just 2 things I noticed.

Also get rid of that "GetDesktopWindow();" from your create window function.

CreateWindow("app","app",WS_OVERLAPPED,
50,50,iAppWidth+8, iAppHeight+34,NULL,NULL,hInst,NULL);

Isn''t amazing how we always assume it''s the device?

Share this post


Link to post
Share on other sites
quote:
Original post by RhoneRanger
Maybe it's just me but I don't think your WNDCLASSEX is complete.

ANother thing I found strange right off the bat, but thought I was loony, is that you are using a WNDCLASSEX but are not calling createWindowEx.

I dunno, those are just 2 things I noticed.

Also get rid of that "GetDesktopWindow();" from your create window function.

CreateWindow("app","app",WS_OVERLAPPED,
50,50,iAppWidth+8, iAppHeight+34,NULL,NULL,hInst,NULL);

Isn't amazing how we always assume it's the device?



His WNDCLASSEX structure is complete. There are 12 members. Also, you don't have to use CreateWindowEx when using RegisterClassEx. They are not related.

But, you're right. We tend to be so focused on DirectX that that we tend to forget those silly Win32 things. "DirectX MUST be completely hosed. It CAN'T be all that silly stuff I did before trying to get DirectX going."

edit - RegisterWindowEx -> RegisterClassEx = brainfart.

[edited by - Dave Hunt on December 16, 2003 11:14:32 AM]

Share this post


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

Share this post


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

Share this post


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

Share this post


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

INT 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]

Share this post


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

Share this post


Link to post
Share on other sites