Jump to content
  • Advertisement

Archived

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

twan

direct 3d init with a class (unresolved error)

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

I get a the next error : TEST fatal error LNK1120: 1 unresolved externals TEST error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "public: void __thiscall CDirect3D::Init_D3D(void)" (?Init_D3D@CDirect3D@@QAEXXZ) I realy realy don't have a glue why i get the error. Can somebody please help me with this ?
#include <d3d9.h>

class CDirect3D
{
public:  
  void Init_D3D();
  void Kill_D3D();
};

struct Global
{
  bool AppDone;
  HINSTANCE Instance;
  HWND Window;
  int ScreenWidth;
  int ScreenHeight;
} g;

CDirect3D D3D;

PDIRECT3D9 pD3D;
LPDIRECT3DDEVICE9 pD3D_Device;

int APIENTRY WinMain(HINSTANCE p_instance,HINSTANCE p_prev_instance,LPSTR p_cmd_line,int p_show);
LRESULT CALLBACK default_window_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
bool Init_Window();
void Kill_Window();

int APIENTRY WinMain(HINSTANCE p_instance,HINSTANCE p_prev_instance,LPSTR p_cmd_line,int p_show)
{
  MSG msg;

  g.ScreenWidth=800;
  g.ScreenHeight=600;
  g.AppDone= false;

  g.Instance=p_instance;
  Init_Window();

  D3D.Init_D3D();

	while(!g.AppDone)
	{
		if(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

  D3D.Kill_D3D();

	return 0;
}

LRESULT CALLBACK default_window_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
  switch(msg)
	{
		case WM_KEYDOWN:  // A key has been pressed, end the app
			switch(wparam)
			{
				case VK_ESCAPE:
					g.AppDone=true;
					return 0;
			}
			return 0;

		case WM_DESTROY:  //This window is being destroyed, tell Windows we're quitting
			PostQuitMessage(0);
			return 0;
	}
	return (DefWindowProc(hwnd,msg,wparam,lparam));
}

bool Init_Window()
{
  WNDCLASS window_class;
  DWORD style;

  window_class.style          = CS_OWNDC;
  window_class.cbClsExtra     = 0;
  window_class.cbWndExtra     = 0;
  window_class.hInstance      = g.Instance;
  window_class.hIcon          = LoadIcon(NULL,IDI_APPLICATION);
  window_class.hCursor        = LoadCursor(NULL,IDC_ARROW);
  window_class.hbrBackground  = (HBRUSH)GetStockObject(BLACK_BRUSH);
  window_class.lpszMenuName   = NULL;
  window_class.lpszClassName  = "DX9";
  window_class.lpfnWndProc    = default_window_proc;

  RegisterClass(&window_class);

  style=WS_POPUP;

  g.Window=CreateWindow("DX9", "DX9",style, 0,0,g.ScreenWidth,g.ScreenHeight, NULL, NULL, g.Instance, NULL);

  return true;
}

void Kill_Window()
{
  if(g.Window)
	{
    if(!DestroyWindow(g.Window))
		{
    }
		else
		{
      MSG msg;
      while(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
			{
        DispatchMessage(&msg);
      }
		}
    g.Window=NULL;
  }
  UnregisterClass("DX9",g.Instance);
}

void CDirect3D::Init_D3D()
{
	HRESULT hr;
	D3DPRESENT_PARAMETERS d3dpp;

	pD3D = Direct3DCreate9(D3D_SDK_VERSION);

  ZeroMemory(&d3dpp,sizeof(d3dpp));

  d3dpp.BackBufferWidth        = g.ScreenWidth;
  d3dpp.BackBufferHeight       = g.ScreenHeight;
  d3dpp.BackBufferFormat       = D3DFMT_R5G6B5;
  d3dpp.BackBufferCount        = 1;  //We only need a single back buffer
  d3dpp.MultiSampleType        = D3DMULTISAMPLE_NONE;
  d3dpp.MultiSampleQuality     = 0;
  d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD; // Throw away previous frames, we don't need them
  d3dpp.hDeviceWindow          = g.Window;  //This is our main (and only) window
  d3dpp.Windowed               = FALSE;
  d3dpp.EnableAutoDepthStencil = false;
  d3dpp.Flags                  = 0;

  hr=pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g.Window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pD3D_Device);
}

void CDirect3D::Kill_D3D()
{
	if(pD3D_Device)
	{
		pD3D_Device->Release();
		pD3D_Device=NULL;
	}
	if(pD3D)
	{
		pD3D->Release();
		pD3D=NULL;
	}
}
  
[edited by - twan on March 25, 2004 3:40:17 PM]

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!