error LNK2019: 无法解析的外部符号 _Direct3DCreate9@4???

butterflygogogo 2009-08-19 10:43:47
环境 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++目录 添加过了 但是还是不行 请大侠指教一下啊
...全文
1519 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
fblgzdq 2009-08-20
  • 打赏
  • 举报
回复
hui
  • 打赏
  • 举报
回复
http://topic.csdn.net/t/20030423/11/1697151.html

Project -->Setting-->Link
Add library (.lib file) used.
fblgzdq 2009-08-19
  • 打赏
  • 举报
回复
回一个
butterflygogogo 2009-08-19
  • 打赏
  • 举报
回复
给分
zgjxwl 2009-08-19
  • 打赏
  • 举报
回复
另外。。。
#include <D3d9.h>
zgjxwl 2009-08-19
  • 打赏
  • 举报
回复
应该是需要的库没引入

具体可以在代码中加上
#pragma comment( lib, "要引入的库名" )
或者

也可以在project--》setting--》link--》object/library modules
在这个框里把要引入的库 粘贴进去
Subye 2009-08-19
  • 打赏
  • 举报
回复
首先库文件跟包含文件都要添加好~
然后链接那几个静态库~
程序开头写
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
"项目-属性-配置属性-链接器-输入"也能设置
功能同上~
  • 打赏
  • 举报
回复
在你的代码中添加

#pragma comment( lib ,"库的名字" )
mstlq 2009-08-19
  • 打赏
  • 举报
回复
2003的做法是……
项目-属性-链接器-输入-附加依赖项……

2005应该大同小异^_^
butterflygogogo 2009-08-19
  • 打赏
  • 举报
回复
在visual studio.net 2005下怎么添加库啊 ?
mstlq 2009-08-19
  • 打赏
  • 举报
回复
http://dpic.dpnet.com.cn/user1/1935072/archives/2008/177418.shtml

缺库……

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧