[巨额悬赏]ASP.Net底层开发问题,调用DLL,IIS6高手入
在IIS6下使用ASP.Net[DllImport(" 调用非托管加密狗的dll,然后IIS6停止响应,
程序在IIS5下无错,执行正常,在Windows2003+VS2005下调试无错,执行正常,但是在IIS6下就出错了,症状为IIS无响应
排除加密狗DLL内部接口问题,调用代码问题,并设置IIS6服务为IIS5模式,启用了父路径,启用IIS和桌面交互的服务
IIS6
示例调用代码:
public class DllInvoke
{
//引用系统方法来取得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);
[DllImport("user32.dll", EntryPoint = "MessageBox")]
public static extern int MessageBox(int hWnd, String strMessage, String strCaption, uint uiType);
private IntPtr hLib;
public DllInvoke(String DLLPath)
{
this.hLib = LoadLibrary(DLLPath);
}
~DllInvoke()
{
FreeLibrary(this.hLib);
}
//将要执行的函数转换为委托
public Delegate Invoke(String APIName, Type t)
{
IntPtr api = GetProcAddress(this.hLib, APIName);
return (Delegate)Marshal.GetDelegateForFunctionPointer(api, t);
}
}
--------------------
调用
DllInvoke dll = new DllInvoke(Server.MapPath(@"~/Bin/XXX.dll"));
按地址载入调用dll
XXX_GetNetState GetNetState = (XXX_GetNetState)dll.Invoke("XXX_GetNetState", typeof(XXX_GetNetState));
转换为委托方法
int status = GetNetState();
下面是传递参数例子: