问题是32位演示静态链接到32位DLL,而64位演示静态链接到64位DLL。作为.NET应用程序,它可以在客户端PC上作为32位或64位进程运行。
.NET 4.0框架提供了Environment.Is64BitProcess属性,如果应用程序作为64位进程运行,则返回true。
我想要做的是在检查Is64BitProcess属性后动态加载正确的DLL。然而,当我研究动态加载库时,总是得到以下结果:
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32.dll")]
public static extern bool FreeLibrary(IntPtr hModule);
看起来这些方法是专门针对32位操作系统的。是否有64位的替代品?
如果根据Is64BitProcess检查调用适当的方法,同时静态链接32位和64位库,是否会引起问题?
public class key32
{
[DllImport("KEYDLL32.DLL", CharSet = CharSet.Auto)]
private static extern uint KFUNC(int arg1, int arg2, int arg3, int arg4);
public static bool IsValid()
{
... calls KFUNC() ...
}
}
public class key64
{
[DllImport("KEYDLL64.DLL", CharSet = CharSet.Auto)]
private static extern uint KFUNC(int arg1, int arg2, int arg3, int arg4);
public static bool IsValid()
{
... calls KFUNC() ...
}
}
...
if (Environment.Is64BitProcess)
{
Key64.IsValid();
}
else
{
Key32.IsValid();
}
谢谢!