文件名称:从指定文件byte[]内存数组加载非托管DLL API
文件大小:13KB
文件格式:DLL
更新时间:2014-12-26 10:46:28
内存加载非托管DLL 内存加载
C#可以很轻松从内存或资源加载托管DLL..但C++ kernel32.dll LoadLibrary只能加载指定路径非托管DLL..有了kernel.dll现在好了.可以像C#一样轻松从内存或资源里加载非托管DLL.. 从指定文件byte[]内存数组加载非托管DLL API 此DLL接口 FARPROC MemLoadLibrary(void* lpFileData, int nDataLength); FARPROC MemGetProcAddress(FARPROC handle,LPCSTR lpProcName); BOOL MemFreeLibrary(FARPROC handle); 模仿了kernel32.dll 的LoadLibrary操作方式..以下是C#调用示例 C#示例 #region " DllImport " [DllImport("kernel.dll", EntryPoint = "MemLoadLibrary")] public extern static IntPtr LoadLibrary(ref byte buf, int nLen); [DllImport("kernel.dll", EntryPoint = "MemGetProcAddress")] public extern static IntPtr GetProcAddress(IntPtr handle, String funcName); [DllImport("kernel.dll", EntryPoint = "MemFreeLibrary")] public extern static bool FreeLibrary(IntPtr handle); #endregion