copy Bookmark http://pursuit.blog.tongji.net
上一篇 / 下一篇 2008-04-08 18:24:40 / 个人分类:c++
主要参考了两篇文章《C#中简单调用c/c++旧模块》 和《基于Visual C++6.0的DLL编程实现》,复杂的理论和概念就不说了,简略地写一个实现的全过程吧:
1、在Visual Studio 6.0中用C++语方创建dll文件。
新建工程时选择”Win32 Dynamic-link library ”,在MyDll.h文件中按如下方式声明函数:
#define LIBEXPORT_API extern "C" __declspec(dllexport)
LIBEXPORT_API int Max(int a, int b);
在MyDll.cpp中实现这个函数。
生成MyDll.dll和MyDll.lib。
2、在Visual C# .net中引用dll文件
将MyDll.dll和MyDll.lib拷贝到可执行文件目录下。
添加引用using System.Runtime.InteropServices;
按如下方式声明一个将要引用MyDll.dll中函数的类:
public class RefComm { [DllImport("LibEncrypt.dll", EntryPoint="Max", // 注意:引号内必须为完整的函数名,不能有空格 CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)] public static extern int Max (int a,int b); }
使用如下语句调用:
int iSum = RefComm.Max(2,3);
引用:
http://www.alixixi.com/Dev/Web/ASPNET/aspnet3/2007/2007050734689.html
http://www.itpub.net/archiver/tid-825811.html
http://www.vckbase.com/document/viewdoc/?id=1370
http://blog.csdn.net/notno/archive/2006/07/17/932335.aspx
http://gongyuzhuo.blog.163.com/blog/static/36304420076311305926/
http://www.pcvz.com/Program/Programs/CCC/CCCsystem/Program_98258.html
http://blog.csdn.net/pansiom/archive/2006/01/01/568096.aspx
http://blog.chinaunix.net/u/18297/showart_296028.html
导入论坛 引用链接 收藏 分享给好友 推荐到圈子 管理 举报
TAG:
评分:0
显示全部
内容
昵称
验证
提交评论