Example #1
0
 public void UnloadSwitchingLibrary()
 {
     lock (nativeSynchronizer)
     {
         if (pMqeDll != IntPtr.Zero)
         {
             NativeMQEDll.FreeLibrary(pMqeDll);
             pMqeDll = IntPtr.Zero;
         }
     }
 }
Example #2
0
        public void InitializeNativeApis(string mode)
        {
            try
            {
                lock (nativeSynchronizer)
                {
                    if (nativeDllPath == null)
                    {
                        nativeDllPath = CommonServices.GetInstallationPath();//读取安装地址 吴冬
                        nativeDllPath = "C:\\Program Files (x86)\\IBM\\WebSphere MQ";
                        //nativeDllPath = System.Environment.CurrentDirectory;

                        nativeDllPath = nativeDllPath.TrimEnd(new char[] { '\\' });
                        if (CommonServices.Is64bitCLR())
                        {
                            nativeDllPath = nativeDllPath + @"\bin64\";
                        }
                        else
                        {
                            nativeDllPath = nativeDllPath + @"\bin\";
                        }
                        pMqeDll = NativeMQEDll.LoadLibrary(nativeDllPath + "mqe.dll");
                        if (pMqeDll == IntPtr.Zero)
                        {
                            throw new Exception("Failed to load mqe.dll from folder " + nativeDllPath);
                        }
                    }
                    Type importedApis = null;
                    if ((mode == "MQSeries Client") && !unmanagedInitialized)
                    {
                        importedApis = ImportNativeApis(typeof(NativeUnmanaged), "NativeUnmanaged", mode);
                        this.InitializeNativeCommonApis(importedApis);
                        this.InitializeUnmanagedSpecificApis(importedApis);
                        unmanagedInitialized = true;
                    }
                    else if ((mode == "MQSeries XA Client") && !unmanagedXaInitialized)
                    {
                        importedApis = ImportNativeApis(typeof(NativeXAUnmanaged), "NativeXAUnmanaged", mode);
                        this.InitializeNativeCommonApis(importedApis);
                        this.InitializeUnmanagedXASpecificApis(importedApis);
                        unmanagedXaInitialized = true;
                    }
                    else if ((mode == "MQSeries Bindings") && !bindingsInitialized)
                    {
                        importedApis = ImportNativeApis(typeof(NativeBindings), "NativeBindings", mode);
                        this.InitializeNativeCommonApis(importedApis);
                        this.InitializeBindingsSpecificApis(importedApis);
                        bindingsInitialized = true;
                    }
                    else if ((mode == "IBM.WMQ.MQCommonServices") && !commonServiceInitialized)
                    {
                        InitializeCommonServiceApis(ImportNativeApis(typeof(NativeCommonService), "NativeCommonService", mode));
                        commonServiceInitialized = true;
                    }
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }