asp.net调用vc dll
2008-09-24 09:35
288 查看
public class DllInvoke
{
[DllImport("kernel32.dll")]
private extern static IntPtr LoadLibrary(String path);
[DllImport("kernel32.dll")]
private extern static IntPtr GetProcAddress(IntPtr lib,String funcName);
[DllImport("kernel32.dll")]
private extern static bool FreeLibrary(IntPtr lib);
private IntPtr hLib;
public DllInvoke(String DLLPath1,String DLLPath2)
{
LoadLibrary(DLLPath2);
hLib = LoadLibrary(DLLPath1);
}
~DllInvoke()
{
FreeLibrary(hLib);
}
//将要执行的函数转换为委托
public Delegate Invoke(String APIName,Type t)
{
IntPtr api = GetProcAddress(hLib,APIName);
return (Delegate)Marshal.GetDelegateForFunctionPointer(api,t);
}
}
//使用
public class DecryptCommon
{
public delegate bool Decrypt(StringBuilder encryptKey, StringBuilder outKey);
public DecryptCommon()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static bool getDecrypt(StringBuilder encryptKey, out StringBuilder outKey)
{
DllInvoke dll = new DllInvoke(System.Web.HttpContext.Current.Server.MapPath(@"~/Bin/Decrypt.dll"), System.Web.HttpContext.Current.Server.MapPath(@"~/Bin/DES3.DLL"));
Decrypt decrypt = (Decrypt)dll.Invoke("Decrypt", typeof(Decrypt));
outKey =new StringBuilder(20);
return decrypt(encryptKey, outKey);
}
//解密
public static string getMiMa(string encryptKey)
{
StringBuilder sbEncryptKey = new StringBuilder();
sbEncryptKey.Append(encryptKey);
StringBuilder value = null;
getDecrypt(sbEncryptKey, out value);
return value.ToString();
}
//解密
public static bool getMiMaBool(string encryptKey)
{
StringBuilder sbEncryptKey = new StringBuilder();
sbEncryptKey.Append(encryptKey);
StringBuilder value = null;
return getDecrypt(sbEncryptKey, out value);
}
}
从网上找到了上面的代码,要是一个dll调用另外一个dll 怎么办呢,注意红色部分
{
[DllImport("kernel32.dll")]
private extern static IntPtr LoadLibrary(String path);
[DllImport("kernel32.dll")]
private extern static IntPtr GetProcAddress(IntPtr lib,String funcName);
[DllImport("kernel32.dll")]
private extern static bool FreeLibrary(IntPtr lib);
private IntPtr hLib;
public DllInvoke(String DLLPath1,String DLLPath2)
{
LoadLibrary(DLLPath2);
hLib = LoadLibrary(DLLPath1);
}
~DllInvoke()
{
FreeLibrary(hLib);
}
//将要执行的函数转换为委托
public Delegate Invoke(String APIName,Type t)
{
IntPtr api = GetProcAddress(hLib,APIName);
return (Delegate)Marshal.GetDelegateForFunctionPointer(api,t);
}
}
//使用
public class DecryptCommon
{
public delegate bool Decrypt(StringBuilder encryptKey, StringBuilder outKey);
public DecryptCommon()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static bool getDecrypt(StringBuilder encryptKey, out StringBuilder outKey)
{
DllInvoke dll = new DllInvoke(System.Web.HttpContext.Current.Server.MapPath(@"~/Bin/Decrypt.dll"), System.Web.HttpContext.Current.Server.MapPath(@"~/Bin/DES3.DLL"));
Decrypt decrypt = (Decrypt)dll.Invoke("Decrypt", typeof(Decrypt));
outKey =new StringBuilder(20);
return decrypt(encryptKey, outKey);
}
//解密
public static string getMiMa(string encryptKey)
{
StringBuilder sbEncryptKey = new StringBuilder();
sbEncryptKey.Append(encryptKey);
StringBuilder value = null;
getDecrypt(sbEncryptKey, out value);
return value.ToString();
}
//解密
public static bool getMiMaBool(string encryptKey)
{
StringBuilder sbEncryptKey = new StringBuilder();
sbEncryptKey.Append(encryptKey);
StringBuilder value = null;
return getDecrypt(sbEncryptKey, out value);
}
}
从网上找到了上面的代码,要是一个dll调用另外一个dll 怎么办呢,注意红色部分
相关文章推荐
- asp.net调用vc dll,部署在iis7中无效
- Asp.NET调用C++写的dll
- ASP.NET/C#中如何调用动态链接库DLL
- AjaxPro.dll,asp.net 前台js调用后台方法(无刷新)
- Asp.NET调用C++写的dll
- asp.net教程-如何利用C#创建和调用DLL
- vc++.net的mfc做dll或调用都类似vc6
- ASP.NET调用DLL
- asp.net C# 调用 delphi的dll
- ASP.net/C#中如何调用动态链接库DLL
- C#调用VC++.net托管库程序集DLL
- asp.net调用C++的dll
- asp.net 调用(引用 Native dll 的)C++/CLI dll 的问题及解决
- ASP.NET中调用自定义DLL
- 关于在VB.NET中调用使用VC++编写的类库dll的一点笔记
- 在C#.net中调用VC 6.0编写的DLL文件
- 从 ASP.NET 应用程序调用 Microsoft Visual Basic 6.0 DLL 时,使用 Microsoft Visual Studio .NET 本机调试器调试它
- C#调用VC++.net托管库程序集DLL
- Asp.NET调用C++写的dll
- AjaxPro.dll,asp.net 前台js调用后台方法(无刷新)