用C写了一个标准的dll。在开发环境及测试服务器上该dll可以正常加载(动态加载),但部署到虚拟主机中却无法加载。Dll的路径都正确,且是绝对路径。代码如下://动态加载dll类
class DllInvoke
{
[DllImport("kernel32.dll",SetLastError=true)]
private extern static IntPtr LoadLibraryEx(String libPath,IntPtr hFile,Int32 dwFlag); [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 libPath)
{
问题就在这,老说加载失败(hLib=0),Marshal.GetLastWin32Error()为:183.
换成LoadLibraryEx也是一样。
hLib = LoadLibrary(libPath);//该路径传进来没有问题,是绝对路径
//hLib = LoadLibraryEx(libPath, IntPtr.Zero, 16);
if (hLib == IntPtr.Zero)
{
throw new Exception("LoadLibary failure!");
}
} public Delegate GetDelegate(String func, Type t)
{
IntPtr api = GetProcAddress(hLib, func); return api == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer(api, t);
} ~DllInvoke()
{
FreeLibrary(hLib);
}
} class Encrypter
{
delegate Int32 DEncrypter(ref Byte source, Int32 sourceLen);
private String dllPath = ConfigurationManager.AppSettings.Get("Encrypt");
private DllInvoke invoke; public Encrypter() {
String dllFilePath = System.Web.HttpContext.Current.Server.MapPath(dllPath);
invoke = new DllInvoke(dllFilePath);
} public bool Encrypt(Byte[] source)
{
DEncrypter encrypt = (DEncrypter)invoke.GetDelegate("Encrypt", typeof(DEncrypter)); return encrypt(ref source[0], source.Length) == 0 ? true : false;
}
}
这段程序在开发环境及部署到测试服务器上都成功运行,但已部署到虚拟主机上就报错。
xdjm们哪个知道是什么原因啊,急啊,都已经4天了,头大啊
class DllInvoke
{
[DllImport("kernel32.dll",SetLastError=true)]
private extern static IntPtr LoadLibraryEx(String libPath,IntPtr hFile,Int32 dwFlag); [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 libPath)
{
问题就在这,老说加载失败(hLib=0),Marshal.GetLastWin32Error()为:183.
换成LoadLibraryEx也是一样。
hLib = LoadLibrary(libPath);//该路径传进来没有问题,是绝对路径
//hLib = LoadLibraryEx(libPath, IntPtr.Zero, 16);
if (hLib == IntPtr.Zero)
{
throw new Exception("LoadLibary failure!");
}
} public Delegate GetDelegate(String func, Type t)
{
IntPtr api = GetProcAddress(hLib, func); return api == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer(api, t);
} ~DllInvoke()
{
FreeLibrary(hLib);
}
} class Encrypter
{
delegate Int32 DEncrypter(ref Byte source, Int32 sourceLen);
private String dllPath = ConfigurationManager.AppSettings.Get("Encrypt");
private DllInvoke invoke; public Encrypter() {
String dllFilePath = System.Web.HttpContext.Current.Server.MapPath(dllPath);
invoke = new DllInvoke(dllFilePath);
} public bool Encrypt(Byte[] source)
{
DEncrypter encrypt = (DEncrypter)invoke.GetDelegate("Encrypt", typeof(DEncrypter)); return encrypt(ref source[0], source.Length) == 0 ? true : false;
}
}
这段程序在开发环境及部署到测试服务器上都成功运行,但已部署到虚拟主机上就报错。
xdjm们哪个知道是什么原因啊,急啊,都已经4天了,头大啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货