错误LNK2001:无法解析的外部符号_IID_IDirectDraw2 [英] error LNK2001: unresolved external symbol _IID_IDirectDraw2

查看:217
本文介绍了错误LNK2001:无法解析的外部符号_IID_IDirectDraw2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一段使用直接绘图的遗留代码,而我处于相当尴尬的境地.
不久前,我已经更新了系统,不得不适应新的情况(加载ddraw.dll),并且一切正常.
今天,我探索了另一个旧的解决方案,该解决方案共享已更改的文件,但是我遇到了上述链接错误.我检查并比较了项目属性,发现它们很好缝.

这是用于DirectX初始化的代码,麻烦的"代码为粗体.

I work with piece of legacy code which uses direct draw and I''m in rather embarrassing situation.
Not long ago I''ve updated my system and had to adapt to the new situation (loading ddraw.dll) and everything worked fine.
Today I explored another legacy solution which shares files I''ve changed, but I''m stuck with above mentioned linking error. I''ve checked and compared project properties and they seam fine.

This is code for directX initialization, "troublesome" code is bold.

typedef int (__stdcall *DirectDrawCreateFunc)(GUID FAR* a ,LPDIRECTDRAW FAR* b, IUnknown FAR* c);

/* init_directx:
 *  Low-level DirectDraw initialization routine.
 */
int CDCUtils::init_directx(HWND allegro_wnd)
{
   LPDIRECTDRAW directdraw1;
   HRESULT hr;
   LPVOID temp;
   HINSTANCE ddraw = LoadLibrary("%WINDIR%\system32\ddraw.dll");
   if(ddraw== NULL)
   {
	   return -1;
   }
   _ddrawLib =ddraw;
DirectDrawCreateFunc ddFunc = (DirectDrawCreateFunc)GetProcAddress(ddraw,"DirectDrawCreate");
if(ddFunc)
{
 /* first we have to set up the DirectDraw1 interface... */
   hr = ddFunc(NULL, &directdraw1, NULL);
   if (FAILED(hr))
      return -1;
}

   ///* first we have to set up the DirectDraw1 interface... */
   //hr = DirectDrawCreate(NULL, &directdraw1, NULL);
   //if (FAILED(hr))
   //   return -1;

   //...then query the DirectDraw2 interface
   //This is the only place where IID_IDirectDraw2 is mentioned in entire solution
   hr=directdraw1->QueryInterface(IID_IDirectDraw2, &temp);
   if (FAILED(hr))
      return -1;

   _directdraw = (LPDIRECTDRAW2)temp;
   directdraw1->Release();

   /* set the default cooperation level */
   hr = IDirectDraw2_SetCooperativeLevel(_directdraw, allegro_wnd, DDSCL_NORMAL);
   if (FAILED(hr))
      return -1;

   /* get capabilities */
   _ddcaps.dwSize = sizeof(_ddcaps);
   hr = IDirectDraw2_GetCaps(_directdraw, &_ddcaps, NULL);
   if (FAILED(hr)) {
      TRACE("Can''t get driver caps\n");
      return -1;
   }

   _dxHwnd=allegro_wnd;
  return 0;
} 


有什么想法吗?
为什么它只能在一种解决方案中起作用而不能在这种解决方案中起作用?
哦,链接器,我讨厌您.


Any ideas?
Why it works in one solution and not in this one?
Oh linker I loathe thee.

推荐答案

您很可能忘记了在 Link 中提供相应的 .lib 文件. >项目属性的标签.
找出该接口所需的.lib,然后将其填写在链接"选项卡中.

否则,可能是版本问题:检查代码中使用的DirectX版本是否与系统上安装的DirectX SDK匹配.

---------------------------------------

此问题来自库问题.有某种方式我.lib缺少某个地方或版本不正确:
-检查两个项目是否使用相同版本的DirectX(检查链接器中包含的.h目录和.lib文件)
-在项目选项中的C/C ++下检查其他包含目录
-检查项目选项中链接下的其他图书馆目录
-我甚至建议仅保留一个版本(从旧版本中删除所有剩余的.h,.lib或.dll文件)
-如果您使用的Visual Studio版本不同,请检查所有默认目录是否相同:菜单工具,选项,项目和解决方案,VC ++目录,库文件包含文件
-正如Albert所建议的,请检查您的代码是否直接通过#pragma comment
Most likely you forgot to provide the corresponding .lib file in the Link tab of your project properties.
Find out which .lib you need for this interface and just fill it in the Link tab.

Otherwise, it might be a version issue: check that the version of DirectX you use in your code matches the DirectX SDK installed on your system.

---------------------------------------

This problem comes from a library problem. There is somehow i .lib missing somewhere or incorrect version:
- Check that both projects use the same version of DirectX (check the included .h directories and .lib files provided in the linker)
- Check the Additionnal Include Directories under C/C++ in project options
- Check the Additionnal Library Directories under Link in project options
- I even recommand to keep only one version (remove all remaining .h, .lib, or .dll files from the old versions)
- If you are working with different versions of Visual Studio, check that all default directories are the same: Menu Tools, Options, Projects and Solutions, VC++ Directories, Library files and Include files
- As Albert suggested check wether your code reference the .lib files directly through a #pragma comment


引用.lib文件. http://www.gamedev.net/topic/7112-linkingerror--iid_idirectdraw2/ [ ^ ]

它提到您可能缺少的.libs.
Here''s a post with someone who had the same problem:
http://www.gamedev.net/topic/7112-linking-error--iid_idirectdraw2/[^]

It mentions what .libs you may be missing.


这篇关于错误LNK2001:无法解析的外部符号_IID_IDirectDraw2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆