• Advertisement
Sign in to follow this  

Was working fine until...

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

hello whoever is reading this i am going through the excersises in Wendy Jone's book "Begining DirectX 9" now i have been looing at this off and on but i always gave up when i couldnt fix something. Now thats going to change. I had a working window and when i added directX code to it i got all these errors and the error report took me to windows.h and im sure there is nothing wrong with that file... but anyways i used VS2k5 Proffessional Edition and DirectX 9.0 If you can, go ahead and take a look at this and tell me where i messed up. thanks very much // Include windows header #include<windows.h> #include<d3d9.h> HINSTANCE hInst; HWND wndHandle; LPDIRECT3D9 pD3D; LPDIRECT3DDEVICE9 pd3dDevice; // Prototypes bool initWindow( HINSTANCE hInstance ); bool initDirect3D(void); void render(void); void cleanUp(void); LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ); // Entry point int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { // Init window if( !initWindow(hInstance)) return false; // Called after initializing window if(!initDirect3D() ) return false; // Message loop MSG msg; ZeroMemory( &msg, sizeof( msg) ); while( msg.message!=WM_QUIT ) { // Check the msg queue if( PeekMessage( &msg, NULL, OU, OU, PM_REMOVE ) ) { TranslateMessage(&msg); DispatchMessage(&msg); } else { render(); } } return (int)msg.wParam; } bool initWindow( HINSTANCE hInstance ) { WNDCLASSEX wcex; // Fill in the wndclassex struct wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = 0; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = "DirectXExample"; wcex.hIconSm = 0; RegisterClassEx(&wcex); // Create the window wndHandle = CreateWindow( "DirectXExample", "DirectXExample", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL); if(!wndHandle) return false; // Display window ShowWindow(wndHandle, SW_SHOW); UpdateWindow(wndHandle); return true; } bool initDirect3D(void) { pD3D = NULL; pd3dDevice = NULL; // Create the DX Obj if( NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION ) ) ) { return false; } // Fill presParams D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof( d3dpp ) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 1; d3dpp.BackBufferHeight = 480; d3dpp.BackBufferWidth = 640; d3dpp.hDeviceWindow = wndHandle; //Create the default DX device if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, wndHandle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice ) ) ) { return false; } return true; } void render(void) { // Check validity of D3D device if( NULL == pd3dDevice ) return; pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); // Pres params pd3dDevice->Present( NULL, NULL, NULL, NULL ); } void cleanUp(void) { // Release device and d3d obj. if( pd3dDevice != NULL ) pd3dDevice->Release( ); if( pD3D != NULL ) pD3D->Release( ); } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { // Check any available msgs switch(message) { case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam); }

Share this post


Link to post
Share on other sites
Advertisement
It would help if you editing your post and put the code in ([)source(])([/)source(]) tags, and also posted the error messages.

Scott

Share this post


Link to post
Share on other sites
Quote:
Original post by CodaKiller
You should delete you other 3 post fast, I don't think the mods will like that...

Yeah and post the exact error message you are getting.
I went through that book several years ago and there are some minor changes you needed to make to get some of the code to compile I remeber that. There were some simple and easy fixes for the most part.

Share this post


Link to post
Share on other sites
sorry about that. I actually didnt know i was a member here so whatever i posted... i never saw again. anyways here it is in source brackets


// Include windows header
#include<windows.h>
#include<d3d9.h>

HINSTANCE hInst;
HWND wndHandle;
LPDIRECT3D9 pD3D;
LPDIRECT3DDEVICE9 pd3dDevice;

// Prototypes
bool initWindow( HINSTANCE hInstance );
bool initDirect3D(void);
void render(void);
void cleanUp(void);
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );

// Entry point
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{
// Init window
if( !initWindow(hInstance))
return false;

// Called after initializing window
if(!initDirect3D() )
return false;

// Message loop
MSG msg;
ZeroMemory( &msg, sizeof( msg) );
while( msg.message!=WM_QUIT )
{
// Check the msg queue
if( PeekMessage( &msg, NULL, OU, OU, PM_REMOVE ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
render();
}
}
return (int)msg.wParam;
}

bool initWindow( HINSTANCE hInstance )
{
WNDCLASSEX wcex;

// Fill in the wndclassex struct
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "DirectXExample";
wcex.hIconSm = 0;
RegisterClassEx(&wcex);

// Create the window
wndHandle = CreateWindow(
"DirectXExample",
"DirectXExample",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);

if(!wndHandle)
return false;

// Display window
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}

bool initDirect3D(void)
{
pD3D = NULL;
pd3dDevice = NULL;

// Create the DX Obj
if( NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION ) ) )
{
return false;
}

// Fill presParams
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferHeight = 480;
d3dpp.BackBufferWidth = 640;
d3dpp.hDeviceWindow = wndHandle;

//Create the default DX device
if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT,
D3DDEVTYPE_REF,
wndHandle,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&pd3dDevice ) ) )
{
return false;
}
return true;
}

void render(void)
{
// Check validity of D3D device
if( NULL == pd3dDevice )
return;
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );

// Pres params
pd3dDevice->Present( NULL, NULL, NULL, NULL );
}

void cleanUp(void)
{
// Release device and d3d obj.
if( pd3dDevice != NULL )
pd3dDevice->Release( );

if( pD3D != NULL )
pD3D->Release( );
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Check any available msgs
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}




and the error messages say...

syntax error missing ; before identifier PVOID64 in winnt.h line 222

missing type specifier int assumed- winnt.h line 222

missing ; before identifier "Buffer" in winnt.h line 5940

missing type specifier in assumed winnt line 5940

missing type specifier int assumed winnt.h line 5940

********************************************************
im sure anyone would have gotten the same error messages if they compiled this.]

and where might i be able to find the changes to this code?

Share this post


Link to post
Share on other sites
Sounds to me like the platform SDK isn't installed or set up correctly. Have you downloaded and installed the platform SDK?

Aside from that, there's a couple of problems with your code:
  • You don't use AdjustWindowRect to get the correct window size, so your backbuffer will be slightly smaller than it should be, which will cause rendering artifacts and will slightly reduce performance.
  • You're creating a reference device, which isn't hardware accelerated, and will render in the order of seconds per frame, rather than frames per second. Is this what you intend?

    Share this post


    Link to post
    Share on other sites
    im just trying to get the example from the book working. its kind of frustrating to hear the books code is wrong... i mean what did i pay 30 dollars for?

    my goal here is to know what to change in the code so it wont have any errors.

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by Evil Steve
    Sounds to me like the platform SDK isn't installed or set up correctly. Have you downloaded and installed the platform SDK?

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by iceman90289
    i couldnt download it off the book's cd so i downloaded the one from Jim Adam's Making RPG's with DirectX 9.0
    That book is pretty old, and was aimed at an older compiler, I wouldn't be surprised if it doesn't work.

    Try getting the Most recent Platform SDK instead. Despite the name, it's for all development, not just 2003 Server.

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by iceman90289
    okay. i am downloading it now. so after this is done i should take another crack at compiling that file?
    Yup. You might need to update your Visual Studio paths first (Tools -> Options -> Projects and Solutions -> VC++ Directories, make sure your new platform SDK is at the top of the list, just under the DirectX SDK in the "Include" and "Lib" filter types).

    Share this post


    Link to post
    Share on other sites
    cool my window shows up now... no complaints from anything. thanks. i guess i can do all the book examples now :)

    and if i decide to go to that jim adams book i mentioned, would i be all set up now? or should i just leave that on my shelf?

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by iceman90289
    cool my window shows up now... no complaints from anything. thanks. i guess i can do all the book examples now :)

    and if i decide to go to that jim adams book i mentioned, would i be all set up now? or should i just leave that on my shelf?
    "Maybe". It uses a pretty old DirectX SDK, and I don't think it'll compile straight out of the book. By all means use it for reference, but be aware that some of the function names and purposes have changed slightly (Mainly in the D3DX library).

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by Evil Steve
    Quote:
    Original post by iceman90289
    cool my window shows up now... no complaints from anything. thanks. i guess i can do all the book examples now :)

    and if i decide to go to that jim adams book i mentioned, would i be all set up now? or should i just leave that on my shelf?
    "Maybe". It uses a pretty old DirectX SDK, and I don't think it'll compile straight out of the book. By all means use it for reference, but be aware that some of the function names and purposes have changed slightly (Mainly in the D3DX library).

    Yeah hopefully you have the 2nd edition of the book which uses DX9 which isn't as hard to fix as the older DX8 version of the book I have!

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by iceman90289
    im just trying to get the example from the book working. its kind of frustrating to hear the books code is wrong... i mean what did i pay 30 dollars for?

    my goal here is to know what to change in the code so it wont have any errors.

    You'll have to get used to it if you plan on coding for long since by the time the book gets printed there is a newer version of the SDK,etc. The better books post updated code and corrections or errata at their websites though so you should always check for that.

    Share this post


    Link to post
    Share on other sites
    Sign in to follow this  

    • Advertisement