使用C ++中的C#库 [英] Using c++ library in c#

查看:147
本文介绍了使用C ++中的C#库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包括C ++库(DLL)在我的C#项目,但每次我这样做时,我得到以下的VS2008的错误信息,有什么建​​议?

Hey guys, I'm trying include c++ library (DLL) in my c# project but every time I do that I get following error message in VS2008, any suggestions??

编辑:这是一个C ++ MFC DLL

It's a C++ MFC DLL


为C:\Users\cholachaguddapv\Desktop\imaging.dll'的引用无法添加。请确保该文件是可访问的,而且它是一个有效的程序集或COM组件。

A reference to 'C:\Users\cholachaguddapv\Desktop\imaging.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

推荐答案

如果它是一个正常的DLL(不COM,不是托管C ++),则不能添加这样的参考。你必须添加的P / Invoke你想在你的DLL调用出口签名(外部静态方法的定义)。

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);

有一个看的的DllImport 在线帮助中属性。

Have a look at the DllImport attribute in the online help.

这篇关于使用C ++中的C#库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆