Why can't I create a DirectX8 Object???

Started by
3 comments, last by Beowulf_ 21 years, 4 months ago
It''s a small project, so I''ll just post up all the source so far. Scroll down ''till you get to the InitD3D() function, I''ve commented the line that will not execute. The error is: ''Direct3dCreate8'' : undeclared identifier Am I doing something wrong?
  

#define WIN32_LEANANDMEAN

#include <windows.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>


#include "D3d8.h"

IDirect3D8 *g_pD3D;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void InitD3D();
void ReleaseD3D();
void Render();

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wc = { sizeof(WNDCLASSEX) };
	//ZeroMemory(&wc, sizeof(WNDCLASSEX);

	wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_CLASSDC;
	wc.lpfnWndProc = WndProc;
	wc.hInstance = GetModuleHandle(NULL);
	wc.lpszClassName = "DirectX8Test";

	RegisterClassEx(&wc);

	HWND hWnd = CreateWindow("DirectX8Test", "Direct X Test", WS_SYSMENU, 100, 100,
		300, 300, GetDesktopWindow(), NULL, wc.hInstance, NULL);

	ShowWindow(hWnd, nCmdShow);

	BOOL bGetMessage;

	MSG msg;

	while(bGetMessage = GetMessage(&msg, NULL, 0, 0))
	{
		if(bGetMessage == false)
		{
			// error handling

		} else {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	
	return (int)msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	case WM_PAINT:
		Render();
		return 0;
	}

	return DefWindowProc(hWnd, message, wParam, lParam);
}

void InitD3D()
{
	g_pD3D = Direct3dCreate8(D3D_SDK_VERSION); // this line

             // will not compile!

}

void ReleaseD3D()
{
}

void Render()
{
}

  
Advertisement
I think it may have something to do with project settings. Does anyone know what an "import library" is? Do I need one to use directX?
Well, I''m not sure why you''re getting ''undeclared identifier'' instead of ''undefined external'' but yes, you need to link with the correct libraries to use DirectX. If you are using Visual C++ 6.0, go into Project->Settings->Link and find the input libraries. (Can''t remember the exact name.) It will have a whole bunch of .lib files listed already. You need to add d3d8.lib, dxguid.lib, and any others you might need. You can find all this information in the DirectX help under "Introducing DirectX"->"Programming DirectX"->"Compiling DirectX Samples"
yes, you need to include a library for direct3D.

If you are using VisC++ it should be under Project->Settings and then the Link tab. Where it says object/library modules enter d3d8.lib

Also, make sure your compiler knows which directory your directX lib files are in. (You can do that under Tool->Options->Directories in VisC++)

[ Demonic Pillbug ]
That fixed it, thanks!

This topic is closed to new replies.

Advertisement