简体   繁体   English

无法使用Visual C ++ 2012创建有效的dll

[英]Cannot create valid dll by using Visual C++ 2012

I tried to create a dll with Visual C++ 2012 by following this walkthrough , but I failed. 我试着通过这个演练用Visual C ++ 2012创建一个dll,但是我失败了。 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. 当我尝试在另一个项目中导入已构建的dll作为参考时,我收到此错误: 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. 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: 这是我的标题和cpp文件:

DLLEXPORT.H DLLEXPORT.H

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

DLLEXPORT.CPP 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. 此外,我也尝试通过此解决方案解决问题,但我收到此错误: TlbImp : error TI1002 : The input file '****.dll' is not a valid type library.

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. Microsoft世界中存在不同类型的DLL(和EXE):本机DLL,由本机C ++(或C)和程序集产生,包含.NET可执行文件。 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). 您已阅读的演练将为您提供本机DLL,而您尝试执行的引用仅适用于.NET程序集(和COM组件)。

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. 因此,您要么必须构建.NET DLL(可能是C ++ / CLI而不是本机C ++),要么将本机DLL链接到本机应用程序(或导入它),而不是在.NET项目中引用它。

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

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