internal static LibraryModule LoadModule(string filePath) { var libraryModule = new LibraryModule(Win32.LoadLibrary(filePath), filePath); if (libraryModule._handle == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); throw new Win32Exception(error, "Cannot load library: " + filePath); } return(libraryModule); }
internal static IClassFactory GetClassFactory(LibraryModule libraryModule, Guid clsid) { IntPtr ptr = libraryModule.GetProcAddress("DllGetClassObject"); var getClassObject = (DllGetClassObject)Marshal.GetDelegateForFunctionPointer(ptr, typeof(DllGetClassObject)); //var classFactoryIid = new Guid("00000001-0000-0000-c000-000000000046"); IClassFactory classFactory; var hresult = getClassObject(ref clsid, ref classFactoryIid, out classFactory); if (hresult != 0) { //throw new Win32Exception(hresult, "Cannot create class factory"); return(null); } return(classFactory); }