error LNK2019: 无法解析的外部符号 _Direct3DCreate9@4???
环境 visual studio.net 2005
dirctx 9 sdk
代码
#include <windows.h>
#include <d3d9.h>
const wchar_t g_szClassName[] = L"myWindowClass";//
HWND hwnd;
//两个全局变量
LPDIRECT3D9 pD3D;
LPDIRECT3DDEVICE9 pd3dDevice;
//LPSTR = "myWindowClass";
// Step 4: the Window Procedure
//初始化函数
/*********************************************************************
* initDirect3D
*********************************************************************/
bool initDirect3D()
{
pD3D = NULL;
pd3dDevice = NULL;
//create direct object
if(NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
{
return false;
}
//fill in the structure
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 = hwnd;
//create direct device
if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_REF,
hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&pd3dDevice)))
{
return false;
}
return true;
}
/*********************************************************************
* render
*********************************************************************/
void render()
{
//check you have a valid direct device
if(NULL == pd3dDevice)
{
return ;
}
pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB( 0,0,255 ), 1.0f, 0);
//present the back buffer contents to the display
pd3dDevice->Present(NULL,NULL,NULL,NULL);
}
///
void cleanUp(void)
{
// Release the device and the Direct3D object
if( pd3dDevice != NULL )
pd3dDevice->Release();
if( pD3D != NULL )
pD3D->Release();
}
///
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
lParam)
{
switch(msg)
{
case WM_LBUTTONDOWN:
MessageBox(NULL,L"zhang",L"jian",MB_OK);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
//direct 初始化 initDirect3D()自己定义的初始化函数
if(!initDirect3D())
{
return false;
}
WNDCLASSEX wc;
MSG Msg;
//Step 1: Registering the Window Class 下面的信息是用来设定窗口的相关属性
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;//
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, L"Window Registration Failed!", L"Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,/// 从注册的类去创建窗口
L"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, L"Window Creation Failed!", L"Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
/* // Step 3: The Message Loop //消息循环
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}*/
if( PeekMessage( &Msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage ( &Msg );
DispatchMessage ( &Msg );
}
else
{
render( );
}
return Msg.wParam;
}
错误提示:
error LNK2019: 无法解析的外部符号 _Direct3DCreate9@4,该符号在函数 "bool __cdecl initDirect3D(void)" (?initDirect3D@@YA_NXZ) 中被引用
我已经在工具-》选项-》项目和解决方案-》vc++目录 添加过了 但是还是不行 请大侠指教一下啊