简体   繁体   English

未解析的外部符号_CLSID_VdsLoader

[英]unresolved external symbol _CLSID_VdsLoader

I'm trying to write a program that can manage the harddisks/volumes/partitions in a Windows system. 我正在尝试编写一个可以管理Windows系统中的硬盘/卷/分区的程序。 It seemed like a good idea to use Windows' Virtual Disk Service to accomplish this. 使用Windows的虚拟磁盘服务来实现这一目标似乎是一个好主意。

I wrote a bit of code to try it out, but when linking it I get the following error: error LNK2001: unresolved external symbol _CLSID_VdsLoader 我写了一些代码来尝试它,但是当链接它时我得到以下错误: error LNK2001: unresolved external symbol _CLSID_VdsLoader

Microsofts sample code indicates that I have to link to ole32.lib, and from googling I learned that uuid.lib is also involved. 微软的示例代码表明我必须链接到ole32.lib,并且通过谷歌搜索我了解到uuid.lib也参与其中。 The "Additional Dependencies" line in my project settings is the following: 我的项目设置中的“附加依赖项”行如下:

kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)

As you can see, both previously mentioned libraries are included. 如您所见,前面提到的两个库都包含在内。

I'm trying all this on Visual C++ Express for Windows Desktop 2013. Could this be the problem? 我正在尝试使用Visual C ++ Express for Windows Desktop 2013。这可能是问题吗? Perhaps the express version does not support 100% of the available COM objects? 也许快递版本不支持100%的可用COM对象? If that's not it, what else could it be? 如果不是这样,还有什么呢?

这里解释了: 如何通过使用DEFINE_GUID来避免错误“LNK2001 unresolved external” ,您只需要在stdafx.h文件中添加#include <InitGuid.h>

I had similar issue with unresolved external guid. 我有与未解决的外部指导相似的问题。 I didn't define _MIDL_USE_GUIDDEF_ macro and tried to compile code as C++ code. 我没有定义_MIDL_USE_GUIDDEF_宏并尝试将代码编译为C ++代码。

Since MIDL compiler generates C source file to define guids it is compiled as C code until you explicitly tell visual studio to compile code as C++ code. 由于MIDL编译器生成C源文件来定义guid,因此它被编译为C代码,直到您明确告诉visual studio将代码编译为C ++代码。

MIDL-generated header file contains (when compiled as C++): MIDL生成的头文件包含(当编译为C ++时):

extern "C"
{
    extern "C" const IID iid;   // extern "C" is redundant, extern would be enough
}

MIDL-generated guids-definition file contains (when compiled as C++): MIDL生成的guids-definition文件包含(当编译为C ++时):

extern "C"
{
    const IID iid = { ... };    // _MIDL_USE_GUIDDEF_ macro is not defined
}

We need to remember: 我们需要记住:

extern "C" block implies C name decoration; e.g.
  extern "C" { int a; }

extern "C" singleton implies C name decoration AND extern semantics; e.g.
  extern "C" int a;

in C++ non-extern namespace-scope const object implies internal linkage; e.g.
  const int a;         // internal linkage
  extern const int b;  // external linkage

With this in mind we can see that header file declares const IID iid with external linkage and C name decoration, whereas guids-definition file defines const IID iid with internal linkage and C name decoration. 考虑到这一点,我们可以看到头文件使用外部链接和C名称修饰声明了const IID iid ,而guids-definition文件定义了具有内部链接和C名称修饰的const IID iid Linkages do not match, therefore they are treated as different entities by linker. 链接不匹配,因此链接器将它们视为不同的实体。 In this case const IID iid with external linkage is left undefined and is later used in the same translation unit. 在这种情况下,具有外部链接的const IID iid未定义,稍后在同一翻译单元中使用。

When you add predefined _MIDL_USE_GUIDDEF_ macro guids-definition file will contain: 当您添加预定义的_MIDL_USE_GUIDDEF_宏时, _MIDL_USE_GUIDDEF_ -definition文件将包含:

extern "C"
{
    extern "C" const IID iid = { ... };    // extern "C" is redundant, extern would be enough
}

So you need to add predefined _MIDL_USE_GUIDDEF_ macro in order to explicitly compile code as C++. 因此,您需要添加预定义的_MIDL_USE_GUIDDEF_宏,以便将代码显式编译为C ++。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM