Example #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

            classFactory.CreateInstance(null, ref iid, out object obj);
            return(obj);
        }
Example #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);
        }
Example #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");
            var hresult         = callback(ref clsid, ref classFactoryIid, out IClassFactory classFactory);

            if (hresult != 0)
            {
                throw new Win32Exception(hresult, "Cannot create class factory");
            }
            return(classFactory);
        }
Example #4
0
 /// <summary>
 /// Creates a new instance of the specified filter from a module.
 /// </summary>
 /// <typeparam name="TFilter">The type of the filter.</typeparam>
 /// <param name="clsid">filter The CLSID.</param>
 /// <param name="name">The name.</param>
 /// <param name="filterType">Type of the filter.</param>
 /// <param name="parserFilter">The parser filter.</param>
 internal static void CreateFilter <TFilter>(LibraryModule module, string clsid, string name, ref Type filterType, ref TFilter parserFilter)
 {
     TraceManager.TraceDebug($"Creating new instance of filter, Name = {name}, CLSID = {clsid}, Module = {module.FilePath}");
     try
     {
         filterType   = Type.GetTypeFromCLSID(new Guid(clsid));
         parserFilter = (TFilter)ComHelper.CreateInstance(module, new Guid(clsid));
     }
     catch (Exception ex)
     {
         TraceManager.TraceError(ex, ex.Message);
         throw new NotSupportedException($"Cannot create the filter: Name = {name}, CLSID = {clsid}, Module = {module.FilePath}", ex);
     }
 }