C# 包装类
/// <summary>
/// 包装类
/// </summary>
public class CryptMath
{
//应用的DLL
[DllImport("testDll.dll",CharSet=CharSet.Ansi)]
public static extern void Crypt(
//指针类型
[MarshalAs(UnmanagedType.LPStr)]
//参数
ref string src,
[MarshalAs(UnmanagedType.LPStr)]
ref string key,
[MarshalAs(UnmanagedType.LPStr)]
ref String str
);
[DllImport("testDll.dll",CharSet=CharSet.Unicode)]
public static extern void DeCrypt(
[MarshalAs(UnmanagedType.LPStr)]
ref String src,
[MarshalAs(UnmanagedType.LPStr)]
ref String key,
[MarshalAs(UnmanagedType.LPStr)]
ref String crypt
);
[DllImport("testDll.dll",CharSet=CharSet.Unicode)]
public static extern void desKey(
[MarshalAs(UnmanagedType.LPStr)]
ref String key,
//值类型
short edf);
[DllImport("testDll.dll",CharSet=CharSet.Unicode)]
public static extern void useKey(
ref long from);
//值类型指针
[DllImport("testDll.dll",CharSet=CharSet.Unicode)]
public static extern void cpKey(ref long into);
[DllImport("testDll.dll",CharSet=CharSet.Unicode)]
public static extern void desCrypt(
[MarshalAs(UnmanagedType.LPStr)]
ref String inblock,
[MarshalAs(UnmanagedType.LPStr)]
ref String outblock);
}
调用函数
//返回值长度
String sOutput = new String('\n', 10);
String sKey = "abcd";
short nKey=0;
CryptMath.desKey(ref sKey, nKey);
CryptMath.desCrypt(ref szSrc, ref sOutput);
MessageBox.Show(sOutput);
CryptMath.desKey(ref sKey, 1);
CryptMath.desCrypt(ref sOutput, ref szSrc);
MessageBox.Show(szSrc);
posted on 2006-03-16 11:41 Lonz's 网络文档集 阅读(1150) 评论(0) 收藏 举报
浙公网安备 33010602011771号