Question

I tried to create a dll with Visual C++ 2012 by following this walkthrough, but I failed. When I tried to import built dll in a different project as a reference, I got this error: A reference to '***.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

I don't understand what my mistake is in code and why I get this error. Here is my header and cpp file:

DLLEXPORT.H

__declspec(dllexport) bool setMute();
__declspec(dllexport) bool setActive();

DLLEXPORT.CPP

#include "DLLEXPORT.H"
bool setMute(){
    //some stuff
}
bool setActive(){
    //some stuff
}

Moreover, I also tried to solve the problem by this solution, but I got this error: TlbImp : error TI1002 : The input file '****.dll' is not a valid type library.

Was it helpful?

Solution

There are different kinds of DLLs (and EXEs) in Microsoft world: native DLLs, prodoced by native C++ (or C) and assemblies, containing .NET executable stuff. The walkthrough you have read will give you a native DLL, while the referencing you try to do is meant only for .NET assemblies (and COM components).

So you either have to build a .NET DLL (which would be C++/CLI and not native C++), or link your native DLL to a native app (or importing it) instead of referencing it in a .NET project.

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