예제 #1
0
        public void Initialize(bool ForceLegacy)
        {
            ThrowIfDisposed();
            if (_library != null)
            {
                return;
            }

            var library = LoadLibrary(ForceLegacy);

            if (library.IsLegacy)
            {
                var libraryFunctions = LoadEntryPointsLegacy(library);
                var functions        = new AccessBridgeNativeFunctionsLegacy(libraryFunctions);
                var events           = new AccessBridgeNativeEventsLegacy(libraryFunctions);

                // Everything is initialized correctly, save to member variables.
                _library   = library;
                _functions = functions;
                _events    = events;
            }
            else
            {
                var libraryFunctions = LoadEntryPoints(library);
                var functions        = new AccessBridgeNativeFunctions(libraryFunctions);
                var events           = new AccessBridgeNativeEvents(libraryFunctions);

                // Everything is initialized correctly, save to member variables.
                _library   = library;
                _functions = functions;
                _events    = events;
            }
            _functions.Windows_run();
            OnInitilized();
        }
예제 #2
0
 private static AccessBridgeLibrary LoadLibrary(bool ForceLegacy)
 {
     try {
         AccessBridgeLibrary library;
         if (ForceLegacy)
         {
             library          = new AccessBridgeLibrary("WindowsAccessBridge.dll");
             library.IsLegacy = true;
         }
         else if (IntPtr.Size == 4)
         {
             try {
                 library = new AccessBridgeLibrary("WindowsAccessBridge-32.dll");
             } catch {
                 try {
                     library          = new AccessBridgeLibrary("WindowsAccessBridge.dll");
                     library.IsLegacy = true;
                 } catch {
                     // Ignore, we'll trow the initial exception
                     library = null;
                 }
                 if (library == null)
                 {
                     throw;
                 }
             }
         }
         else if (IntPtr.Size == 8)
         {
             library = new AccessBridgeLibrary("WindowsAccessBridge-64.dll");
         }
         else
         {
             throw new InvalidOperationException("Unknown platform.");
         }
         return(library);
     } catch (Exception e) {
         var sb = new StringBuilder();
         sb.AppendLine("Error loading the Java Access Bridge DLL.");
         sb.AppendLine("This usually happens if the Java Access Bridge is not installed.");
         if (IntPtr.Size == 8)
         {
             sb.Append("Please make sure to install the 64-bit version of the " +
                       "Java SE Runtime Environment version 7 or later. ");
             sb.AppendFormat("Alternatively, try running the 32-bit version of {0} " +
                             "if a 32-bit version of the JRE is installed.", Assembly.GetEntryAssembly().GetName().Name);
         }
         else
         {
             sb.Append(
                 "Please make sure to install the 32-bit version of the " +
                 "Java SE Runtime Environment version 7 or later.");
         }
         throw new ApplicationException(sb.ToString(), e);
     }
 }
예제 #3
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            if (_events != null)
            {
                _events.Dispose();
            }

            if (_library != null)
            {
                _library.Dispose();
                _functions = null;
                _library   = null;
            }

            _disposed = true;
            OnDisposed();
        }