Ejemplo n.º 1
0
        private void Dispose(bool disposing)
        {
            if (!disposed)
            {
                CloseSourceManager();
                if (disposing)
                {
                    if (hModule != null)
                    {
                        hModule.Dispose();
                        hModule = null;
                    }
                }

                if (twEvent.pEvent != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(twEvent.pEvent);
                    twEvent.pEvent = IntPtr.Zero;
                }
            }
        }
Ejemplo n.º 2
0
        private bool LoadSourceManager()
        {
            if (state >= TwainState.SourceManagerLoaded)
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(WindowsDirectory))
            {
                string path = Path.Combine(WindowsDirectory, TwainDllName);

                if (File.Exists(path))
                {
                    this.hModule = UnsafeNativeMethods.LoadLibraryW(path);
                    if (!hModule.IsInvalid)
                    {
                        IntPtr entry = UnsafeNativeMethods.GetProcAddress(hModule, TwainEntryPoint);
                        if (entry != IntPtr.Zero)
                        {
                            twainEvent          = (TwainDelegates.TwainEvent)Marshal.GetDelegateForFunctionPointer(entry, typeof(TwainDelegates.TwainEvent));
                            twainIdentity       = (TwainDelegates.TwainIdentity)Marshal.GetDelegateForFunctionPointer(entry, typeof(TwainDelegates.TwainIdentity));
                            twainParent         = (TwainDelegates.TwianParent)Marshal.GetDelegateForFunctionPointer(entry, typeof(TwainDelegates.TwianParent));
                            twainUI             = (TwainDelegates.TwainUI)Marshal.GetDelegateForFunctionPointer(entry, typeof(TwainDelegates.TwainUI));
                            twainCapability     = (TwainDelegates.TwainCapability)Marshal.GetDelegateForFunctionPointer(entry, typeof(TwainDelegates.TwainCapability));
                            twainNativeTransfer = (TwainDelegates.TwianNativeTransfer)Marshal.GetDelegateForFunctionPointer(entry, typeof(TwainDelegates.TwianNativeTransfer));
                            twainPendingXfers   = (TwainDelegates.TwianPendingXfer)Marshal.GetDelegateForFunctionPointer(entry, typeof(TwainDelegates.TwianPendingXfer));
                            twainStatus         = (TwainDelegates.TwainStatus)Marshal.GetDelegateForFunctionPointer(entry, typeof(TwainDelegates.TwainStatus));

                            this.state = TwainState.SourceManagerLoaded;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
 internal static extern IntPtr GetProcAddress([In()] SafeLibraryHandle hModule, [In(), MarshalAs(UnmanagedType.LPStr)] string lpProcName);