private bool LoadGirderPlugin(string girderPluginFile)
    {
      string folder = Path.GetDirectoryName(girderPluginFile);
      string parent = Directory.GetParent(folder).FullName;
      SetDllDirectory(parent);

      _pluginDll = LoadLibrary(girderPluginFile);
      if (_pluginDll == IntPtr.Zero)
        throw new InvalidOperationException(String.Format("Failed to call LoadLibrary on girder plugin dll ({0})",
                                                          girderPluginFile));

      try
      {
        IntPtr function;

        function = GetProcAddress(_pluginDll, "gir_version");
        _girVersion = (gir_version) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_version));

        function = GetProcAddress(_pluginDll, "gir_name");
        _girName = (gir_name) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_name));

        function = GetProcAddress(_pluginDll, "gir_description");
        _girDescription = (gir_description) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_description));

        function = GetProcAddress(_pluginDll, "gir_devicenum");
        _girDevicenum = (gir_devicenum) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_devicenum));

        function = GetProcAddress(_pluginDll, "gir_requested_api");
        _girRequestedApi =
          (gir_requested_api) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_requested_api));


        function = GetProcAddress(_pluginDll, "gir_open");
        _girOpen = (gir_open) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_open));

        function = GetProcAddress(_pluginDll, "gir_close");
        _girClose = (gir_close) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_close));


        function = GetProcAddress(_pluginDll, "gir_command_gui");
        if (function != IntPtr.Zero) // Optional.
          _girCommandGui = (gir_command_gui) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_command_gui));

        function = GetProcAddress(_pluginDll, "gir_info");
        if (function != IntPtr.Zero) // Optional.
          _girInfo = (gir_info) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_info));

        function = GetProcAddress(_pluginDll, "gir_event");
        if (function != IntPtr.Zero) // Optional.
          _girEvent = (gir_event) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_event));

        function = GetProcAddress(_pluginDll, "gir_start");
        if (function != IntPtr.Zero) // Optional.
          _girStart = (gir_start) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_start));

        function = GetProcAddress(_pluginDll, "gir_stop");
        if (function != IntPtr.Zero) // Optional.
          _girStop = (gir_stop) Marshal.GetDelegateForFunctionPointer(function, typeof (gir_stop));

        return true;
      }
      catch
      {
        FreeLibrary(_pluginDll);
      }

      return false;
    }
Ejemplo n.º 2
0
        private bool LoadGirderPlugin(string girderPluginFile)
        {
            string folder = Path.GetDirectoryName(girderPluginFile);
            string parent = Directory.GetParent(folder).FullName;

            SetDllDirectory(parent);

            _pluginDll = LoadLibrary(girderPluginFile);
            if (_pluginDll == IntPtr.Zero)
            {
                throw new InvalidOperationException(String.Format("Failed to call LoadLibrary on girder plugin dll ({0})",
                                                                  girderPluginFile));
            }

            try
            {
                IntPtr function;

                function    = GetProcAddress(_pluginDll, "gir_version");
                _girVersion = (gir_version)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_version));

                function = GetProcAddress(_pluginDll, "gir_name");
                _girName = (gir_name)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_name));

                function        = GetProcAddress(_pluginDll, "gir_description");
                _girDescription = (gir_description)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_description));

                function      = GetProcAddress(_pluginDll, "gir_devicenum");
                _girDevicenum = (gir_devicenum)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_devicenum));

                function         = GetProcAddress(_pluginDll, "gir_requested_api");
                _girRequestedApi =
                    (gir_requested_api)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_requested_api));


                function = GetProcAddress(_pluginDll, "gir_open");
                _girOpen = (gir_open)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_open));

                function  = GetProcAddress(_pluginDll, "gir_close");
                _girClose = (gir_close)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_close));


                function = GetProcAddress(_pluginDll, "gir_command_gui");
                if (function != IntPtr.Zero) // Optional.
                {
                    _girCommandGui = (gir_command_gui)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_command_gui));
                }

                function = GetProcAddress(_pluginDll, "gir_info");
                if (function != IntPtr.Zero) // Optional.
                {
                    _girInfo = (gir_info)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_info));
                }

                function = GetProcAddress(_pluginDll, "gir_event");
                if (function != IntPtr.Zero) // Optional.
                {
                    _girEvent = (gir_event)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_event));
                }

                function = GetProcAddress(_pluginDll, "gir_start");
                if (function != IntPtr.Zero) // Optional.
                {
                    _girStart = (gir_start)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_start));
                }

                function = GetProcAddress(_pluginDll, "gir_stop");
                if (function != IntPtr.Zero) // Optional.
                {
                    _girStop = (gir_stop)Marshal.GetDelegateForFunctionPointer(function, typeof(gir_stop));
                }

                return(true);
            }
            catch
            {
                FreeLibrary(_pluginDll);
            }

            return(false);
        }