游戏开发论坛

 找回密码
 立即注册
搜索
查看: 4830|回复: 2

我在工程的link中加了ddraw.lib,怎么还会找不到IID_IDirectDraw7

[复制链接]

34

主题

657

帖子

672

积分

高级会员

Rank: 4

积分
672
发表于 2004-12-18 20:35:00 | 显示全部楼层 |阅读模式
做一人极简单的使用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]

18

主题

573

帖子

573

积分

高级会员

Rank: 4

积分
573
发表于 2004-12-19 02:38:00 | 显示全部楼层

Re:我在工程的link中加了ddraw.lib,怎么还会找不到IID_IDirectDraw7

还需要连接dxguid.lib这个文件

34

主题

657

帖子

672

积分

高级会员

Rank: 4

积分
672
 楼主| 发表于 2004-12-19 10:23:00 | 显示全部楼层

Re:我在工程的link中加了ddraw.lib,怎么还会找不到IID_IDirectDraw7

谢谢,解决了。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-23 19:08

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表