Problems with Visualc++

Started by
4 comments, last by steg 19 years, 9 months ago
I'm new in DirectX technologies and I'm studing the book INTRODUCTION TO 3D GAME PROGRAMMING WITH DIRECTX 9.0 by Frank D.Luna. Ok my doubt is about the initialization of DirectX. I placed the code d3Utiliy.h (above):

#include <d3dx9.h>
namespace d3d
{
    bool InitD3D(
	HINSTANCE hInstance,
	int width, int height,
	bool windowed,
	D3DDEVTYPE deviceType,
	IDirect3DDevice9** device);

    int EnterMsgLoop(
	bool (*ptr_display)(float timeDelta));

	LRESULT CALLBACK WndProc(
		HWND hwnd,
		UINT msg,
		WPARAM wParam,
		LPARAM lParam);

    template<class T> void Release(T t)
    {
	if (t) {
	    t->Release();
	    t = 0;
	}
    }

    template<class T> void Delete(T t)
    {
	if (t) {
	    delete t;
	    t = 0;
	}
    }
}

int d3d::EnterMsgLoop(bool (*ptr_display)(float timeDelta))
{
    MSG msg;
    ::ZeroMemory(&msg, sizeof(MSG));
    static float lastTime = (float)timeGetTime();

    while(msg.message != WM_QUIT) {
	if (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
	    ::TranslateMessage(&msg);
	    ::DispatchMessage(&msg);
	}
	else {
	    float currTime = (float)timeGetTime();
	    float timeDelta = (currTime = lastTime) * 0.001f;
	    ptr_display(timeDelta); // call display function
	    lastTime = currTime;
	}
    }
    return msg.wParam;
}

and the d3dUtility.cpp (above)

#include "d3dUtility.h"

IDirect3DDevice9* Device = 0;

bool Setup()
{
    return true;
}

void Cleanup()
{
}

bool Display(float timeDelta)
{
    if (Device) {
	Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
			  0x00000000, 1.0f, 0);
	Device->Present(0, 0, 0, 0);// present backbuffer
    }
    return true;
}

HRESULT IDirect3DDevice9::Clear(
	DWORD Count,
	const D3DRECT* pRects,
	DWORD Flags,
	D3DCOLOR Color,
	float Z,
	DWORD Stencil
);

LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
    case WM_DESTROY:
	::PostQuitMessage(0);
	break;
    case WM_KEYDOWN:
	if (wParam == VK_ESCAPE)
	    ::DestroyWindow(hwnd);
	break;
    }
    return ::DefWindowProc(hwnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hinstance,
                   HINSTANCE prevInstance,
                   LPSTR      cmdLine,
                   int       showCmd)
{
    if (!d3d::InitD3D(hinstance, 800, 600, true, D3DDEVTYPE_HAL, &Device)) {
	::MessageBox(0, "InitD3D() - FALIED", 0, 0);
	return 0;
    }

    if (!Setup()) {
	::MessageBox(0, "Setup() - FALLED", 0, 0);
	return 0;
    }

    d3d::EnterMsgLoop(Display);
    Cleanup();
    Device->Release();
    return 0;
}

Ok it compiled well, but Visual C++ 6.0 generated three Link Errors: Compiling... d3dUtility.cpp Linking... d3dUtility.obj : error LNK2001: unresolved external symbol "bool __cdecl d3d::InitD3D(struct HINSTANCE__ *,int,int,bool,enum _D3DDEVTYPE,struct IDirect3DDevice9 * *)" (?InitD3D@d3d@@YA_NPAUHINSTANCE__@@HH_NW4_D3DDEVTYPE@@PAPAUIDirect3 DDevice9@@@Z) LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/D3DEx.exe : fatal error LNK1120: 2 unresolved externals Error executing link.exe. Please people I'm trying to understand and program in DirectX... Edited by Coder: Use source tags for large locks of code. Check GDNet Forums FAQ [Edited by - Coder on August 18, 2004 10:21:13 AM]
Advertisement
The first error is because you never defined the body for your InitD3D function. This would probably contain things like calls to Direct3DCreate9(), CreateDevice(), CreateVertexBuffer(), CreateTexture(), etc.

The second error is probably because you created a console application, instead of a standard windows application. Console applications look for the entry function main(), while standard Windows applications look for the entry function WinMain(), which is what you have, and what you want. Easy way to fix that is to just start a new project, and select the correct project type.

And just so you know, you can use [source][/source] tags to put your code in nice white color-coded scrollable boxes. [edit: I see that you already used [code][/code] tags, so that's cool.]
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
I had trouble compiling them too. They are VisualStudio.NET workspaces that are provided as examples.

What I did:

Just make a new Win32 workspace in VC++6, add all of the files for the particular example to the project, then include in the Project->Settings->Link(tab) both "d3d9.lib" and "d3d9x.lib".

Compile :)

That worked on all of the examples for me...Hope this helped.

J
Instead of creating a whole new project, you could just simply change the subsystem from console to windows on the Link page of the project settings. But that is just to fix the last error.
.
Thank you Guys!

Agony about your post:

Quote:The first error is because you never defined the body for your InitD3D function. This would probably contain things like calls to Direct3DCreate9(), CreateDevice(), CreateVertexBuffer(), CreateTexture(), etc.


I didn't understand what you mean with that...
You said that I've never difined a boty for my InitD3D function?
What must I do so? Sorry but I'm new in DirectX...
Thanks again!
He means you need to write the method for InitD3D.

bool InitD3D(HINSTANCE hInstance,             int width,             int height,             bool windowed,             D3DDEVTYPE deviceType,             IDirect3DDevice9** device){  bool bInit = FALSE;  // your code  return bInit;}


Regards,
Steve

If it isn't working, take a bath, have a think and try again...

This topic is closed to new replies.

Advertisement