|
|
做一人极简单的使用DirectDraw的程序,出现如下错误:
Linking...
Startup.obj : error LNK2001: unresolved external symbol _IID_IDirectDraw7
Debug/DDrawDemo.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
这是怎么回事,我已经将ddraw.lib加到工程中的link中了,且在VC中已经将DirectX的lib和include目录加进去了。
我编译windows游戏编译大师技巧中的源代码却不会有这种错误。
下面是代码,就一个文件。
//////////////////////////////////////////////////////////////////////////
// Main.cpp
// 描 述:程序从这里启动
// 作 者:游委宾
// 建立日期:2004/12/18
// 最后修改:2004/12/18
//////////////////////////////////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ddraw.h>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int BIT_PER_PIXEL = 8;
const char* CLASS_NAME= "DirectDraw";
const char* WINDOW_NAME = "Direct Draw Demo";
HWND gMainFormHandle;
LPDIRECTDRAW7 gDirectDraw;
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
int DDInit();
void DDShutDown();
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wndCls;
MSG msg;
wndCls.cbSize = sizeof(WNDCLASSEX);
wndCls.cbClsExtra = 0;
wndCls.cbWndExtra = 0;
wndCls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndCls.hCursor = LoadCursor(hInstance, IDC_ARROW);
wndCls.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wndCls.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
wndCls.hInstance = hInstance;
wndCls.lpfnWndProc = WndProc;
wndCls.lpszClassName = CLASS_NAME;
wndCls.lpszMenuName = NULL;
wndCls.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
if (!RegisterClassEx(&wndCls))
return 0;
gMainFormHandle = CreateWindowEx(0, CLASS_NAME, WINDOW_NAME,
WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
0, 0, hInstance, NULL);
if (!gMainFormHandle)
return 0;
if (!DDInit())
return 0;
ShowWindow(gMainFormHandle, nCmdShow);
UpdateWindow(gMainFormHandle);
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DDShutDown();
return 1;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
}
int DDInit()
{
if (DirectDrawCreateEx(NULL, (void **)&gDirectDraw, IID_IDirectDraw7, NULL) != S_OK)
return 0;
if (gDirectDraw->SetCooperativeLevel(gMainFormHandle, DDSCL_NORMAL) != S_OK)
return 0;
if (gDirectDraw->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, BIT_PER_PIXEL, 0, 0) != S_OK)
return 0;
return 1;
}
void DDShutDown()
{
if (gDirectDraw)
{
gDirectDraw->Release();
gDirectDraw = NULL;
}
}
[em10] |
|