首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#如何引用dll中的函数

2012-04-02 
C#怎么引用dll中的函数code.dll中有一函数:BOOL EncodePassword(CString password, CString &newpas) //加

C#怎么引用dll中的函数
code.dll中有一函数:
BOOL EncodePassword(CString password, CString &newpas) //加密password的内容,加密后的内容放在newpas里。

请问该函数在C#中怎么引用?

[解决办法]
首先把这个DLL文件放到(拷贝)你的BIN目录下,然后在要引用这个方法的类中添加using引用,引用包含这个方法的命名空间
比如你的DLL文件中是这样写的

C# code
namespace test.md5{class MD5{//........}}
[解决办法]
[DllImport("动态库名称", EntryPoint = "函数名称", CallingConvention = CallingConvention.Cdecl)]
public static extern int 你自己定义的函数名(参数,参数要和dll中的一致)


还要加个这样的using:
using System.Runtime.InteropServices;

热点排行