110,534
社区成员
发帖
与我相关
我的任务
分享
[DllImport("Kernel32")]
internal static extern int GetProcAddress(int handle, String funcname);
[DllImport("Kernel32")]
internal static extern int LoadLibrary(String funcname);
[DllImport("Kernel32")]
internal static extern int GetModuleHandle(String funcname);
[DllImport("Kernel32")]
internal static extern int FreeLibrary(int handle);
//定义该方法的委托
public delegate int GetNativeSystemInfo (int hwnd, bool is64bit);
public void LoadLib(string dllName,string methodName)
{
int handle = GetModuleHandle(dllName);
int handle = LoadLibrary(dllName);
int p = GetProcAddress(handle, methodName );
if (p > 0) //如果加载了该函数
{
GetNativeSystemInfo SysInfo = (GetNativeSystemInfo)Marshal.GetDelegateForFunctionPointer(new IntPtr(p), typeof(GetNativeSystemInfo));
SysInfo(ref _sysInfo);
}
else
GetSystemInfo(ref _sysInfo);
}