예제 #1
0
        /// <summary>
        /// Attempts to add a new ACM driver from a file
        /// </summary>
        /// <param name="driverFile">Full path of the .acm or dll file containing the driver</param>
        /// <returns>Handle to the driver</returns>
        public static AcmDriver AddLocalDriver(string driverFile)
        {
            IntPtr handle = NativeMethods.LoadLibrary(driverFile);

            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException("Failed to load driver file");
            }
            var driverProc = NativeMethods.GetProcAddress(handle, "DriverProc");

            if (driverProc == IntPtr.Zero)
            {
                NativeMethods.FreeLibrary(handle);
                throw new ArgumentException("Failed to discover DriverProc");
            }
            IntPtr driverHandle;
            var    result = AcmInterop.acmDriverAdd(out driverHandle,
                                                    handle, driverProc, 0, AcmDriverAddFlags.Function);

            if (result != MmResult.NoError)
            {
                NativeMethods.FreeLibrary(handle);
                throw new MmException(result, "acmDriverAdd");
            }
            var driver = new AcmDriver(driverHandle);

            // long name seems to be missing when we use acmDriverAdd
            if (string.IsNullOrEmpty(driver.details.longName))
            {
                driver.details.longName = "Local driver: " + Path.GetFileName(driverFile);
                driver.localDllHandle   = handle;
            }
            return(driver);
        }
예제 #2
0
        public static AcmDriver AddLocalDriver(string driverFile)
        {
            IntPtr intPtr = NativeMethods.LoadLibrary(driverFile);

            if (intPtr == IntPtr.Zero)
            {
                throw new ArgumentException("Failed to load driver file");
            }
            IntPtr procAddress = NativeMethods.GetProcAddress(intPtr, "DriverProc");

            if (procAddress == IntPtr.Zero)
            {
                NativeMethods.FreeLibrary(intPtr);
                throw new ArgumentException("Failed to discover DriverProc");
            }
            IntPtr   hAcmDriver;
            MmResult mmResult = AcmInterop.acmDriverAdd(out hAcmDriver, intPtr, procAddress, 0, AcmDriverAddFlags.Function);

            if (mmResult != MmResult.NoError)
            {
                NativeMethods.FreeLibrary(intPtr);
                throw new MmException(mmResult, "acmDriverAdd");
            }
            AcmDriver acmDriver = new AcmDriver(hAcmDriver);

            if (string.IsNullOrEmpty(acmDriver.details.longName))
            {
                acmDriver.details.longName = "Local driver: " + Path.GetFileName(driverFile);
                acmDriver.localDllHandle   = intPtr;
            }
            return(acmDriver);
        }