在 C# 中使用 C++ 库 [英] Using c++ library in c#
本文介绍了在 C# 中使用 C++ 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的 c# 项目中包含 c++ 库 (DLL),但每次我这样做时,我都会在 VS2008 中收到以下错误消息,有什么建议吗?
这是一个 C++ MFC DLL
<块引用>---------------------------微软视觉工作室---------------------------无法添加对C:UserscholachaguddapvDesktopimaging.dll"的引用.请确保该文件可访问,并且它是一个有效的程序集或 COM 组件.
解决方案
如果是普通"DLL(不是 COM,不是托管 C++),则不能添加这样的引用.您必须为要在 DLL 中调用的导出添加 p/invoke 签名(外部静态方法定义).
[DllImport("yourdll.dll")]public static extern int ExportToCall(int 参数);
查看 DllImport在线帮助中的属性.
I am trying include c++ library (DLL) in my c# project but every time I do that I get following error message in VS2008, any suggestions?
EDIT: It's a C++ MFC DLL
--------------------------- Microsoft Visual Studio --------------------------- A reference to 'C:UserscholachaguddapvDesktopimaging.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
解决方案
If it is a "normal" DLL (not COM, not managed C++), you cannot add a reference like this. You have to add p/invoke signatures (external static method definitions) for the exports you want to call in your DLL.
[DllImport("yourdll.dll")]
public static extern int ExportToCall(int argument);
Have a look at the DllImport attribute in the online help.
这篇关于在 C# 中使用 C++ 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文