Ejemplo n.º 1
0
        internal static object CreateInstance(LibraryModule libraryModule, Guid clsid)
        {
            var    classFactory = GetClassFactory(libraryModule, clsid);
            var    iid          = new Guid("00000000-0000-0000-C000-000000000046"); // IUnknown
            object obj;

            classFactory.CreateInstance(null, ref iid, out obj);
            return(obj);
        }
Ejemplo n.º 2
0
        public 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);
        }
Ejemplo n.º 3
0
        internal static IClassFactory GetClassFactory(LibraryModule libraryModule, Guid clsid)
        {
            IntPtr ptr      = libraryModule.GetProcAddress("DllGetClassObject");
            var    callback = (DllGetClassObject)Marshal.GetDelegateForFunctionPointer(ptr, typeof(DllGetClassObject));

            var           classFactoryIid = new Guid("00000001-0000-0000-c000-000000000046");
            IClassFactory classFactory;
            var           hresult = callback(ref clsid, ref classFactoryIid, out classFactory);

            if (hresult != 0)
            {
                throw new Win32Exception(hresult, "Cannot create class factory");
            }
            return(classFactory);
        }