Question

I'm trying to write a program that can manage the harddisks/volumes/partitions in a Windows system. It seemed like a good idea to use Windows' Virtual Disk Service to accomplish this.

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

Microsofts sample code indicates that I have to link to ole32.lib, and from googling I learned that uuid.lib is also involved. 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? Perhaps the express version does not support 100% of the available COM objects? If that's not it, what else could it be?

Was it helpful?

Solution

This is explained here: How to avoid error "LNK2001 unresolved external" by using DEFINE_GUID, you just need for example to add #include <InitGuid.h> in your stdafx.h file.

OTHER TIPS

I had similar issue with unresolved external guid. I didn't define _MIDL_USE_GUIDDEF_ macro and tried to compile code as C++ code.

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-generated header file contains (when compiled as 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++):

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. 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.

When you add predefined _MIDL_USE_GUIDDEF_ macro guids-definition file will contain:

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++.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top