コード例 #1
0
		private static IClassFactory GetClassFactoryFromDll(string dllName, string filterPersistClass)
		{
			//Load the dll
			IntPtr dllHandle=Win32NativeMethods.LoadLibrary(dllName);
			if (dllHandle==IntPtr.Zero)
				return null;

			//Keep a reference to the dll until the process\AppDomain dies
			_dllList.AddDllHandle(dllHandle);

			//Get a pointer to the DllGetClassObject function
			IntPtr dllGetClassObjectPtr=Win32NativeMethods.GetProcAddress(dllHandle, "DllGetClassObject");
			if (dllGetClassObjectPtr==IntPtr.Zero)
				return null;

			//Convert the function pointer to a .net delegate
			DllGetClassObject dllGetClassObject=(DllGetClassObject)Marshal.GetDelegateForFunctionPointer(dllGetClassObjectPtr, typeof(DllGetClassObject));

			//Call the DllGetClassObject to retreive a class factory for out Filter class
			Guid filterPersistGUID=new Guid(filterPersistClass);
			Guid IClassFactoryGUID=new Guid("00000001-0000-0000-C000-000000000046"); //IClassFactory class id
			Object unk;
			if (dllGetClassObject(ref filterPersistGUID, ref IClassFactoryGUID, out unk)!=0)
				return null;

			//Yippie! cast the returned object to IClassFactory
			return (unk as IClassFactory);
		}
コード例 #2
0
        /// <summary>
        /// Gets a class factory for a specific COM Class ID.
        /// </summary>
        /// <param name="dllName">The dll where the COM class is implemented.</param>
        /// <param name="filterPersistClass">The requested Class ID.</param>
        /// <returns>IClassFactory instance used to create instances of that class.</returns>
        internal static IClassFactory GetClassFactory(string dllName, Guid filterPersistClass)
        {
            // Load the class factory from the dll.
            // By specifying the flags we allow to search for dependencies in the same folder as the file to be loaded
            // as well as default dirs like System32 and the Application folder.
            IntPtr dllHandle = Utilities.SystemAPI.NativeMethods.LoadLibraryEx(dllName, IntPtr.Zero,
                                                                               Utilities.SystemAPI.NativeMethods.LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | Utilities.SystemAPI.NativeMethods.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);

            if (dllHandle == IntPtr.Zero)
            {
                return(null);
            }

            // Keep a reference to the dll until the process\AppDomain dies.
            DLL_LIST.AddDllHandle(dllHandle);

            //Get a pointer to the DllGetClassObject function
            IntPtr dllGetClassObjectPtr = Utilities.SystemAPI.NativeMethods.GetProcAddress(dllHandle, "DllGetClassObject");

            if (dllGetClassObjectPtr == IntPtr.Zero)
            {
                return(null);
            }

            // Convert the function pointer to a .net delegate.
            DllGetClassObject dllGetClassObject = (DllGetClassObject)Marshal.GetDelegateForFunctionPointer(dllGetClassObjectPtr, typeof(DllGetClassObject));

            // Call the DllGetClassObject to retreive a class factory for out Filter class.
            Guid   baseFilterGuid   = filterPersistClass;
            Guid   classFactoryGuid = typeof(IClassFactory).GUID;
            Object unk;

            if (dllGetClassObject(ref baseFilterGuid, ref classFactoryGuid, out unk) != 0)
            {
                return(null);
            }

            return(unk as IClassFactory);
        }
コード例 #3
0
ファイル: ComHelper.cs プロジェクト: jonishzx/Clover
        private static IClassFactory GetClassFactoryFromDll(string dllName, string filterPersistClass)
        {
            IntPtr dllHandle = Win32NativeMethods.LoadLibrary(dllName);

            if (dllHandle == IntPtr.Zero)
            {
                return(null);
            }


            _dllList.AddDllHandle(dllHandle);


            IntPtr dllGetClassObjectPtr = Win32NativeMethods.GetProcAddress(dllHandle, "DllGetClassObject");

            if (dllGetClassObjectPtr == IntPtr.Zero)
            {
                return(null);
            }


            DllGetClassObject dllGetClassObject = (DllGetClassObject)Marshal.GetDelegateForFunctionPointer(dllGetClassObjectPtr, typeof(DllGetClassObject));


            Guid   filterPersistGUID = new Guid(filterPersistClass);
            Guid   IClassFactoryGUID = new Guid("00000001-0000-0000-C000-000000000046");
            Object unk;

            if (dllGetClassObject(ref filterPersistGUID, ref IClassFactoryGUID, out unk) != 0)
            {
                return(null);
            }


            return(unk as IClassFactory);
        }