/// <summary>
        /// Initializes a new instance of the <see cref="GirderPluginWrapper"/> class.
        /// </summary>
        /// <param name="fileName">Name of the plugin dll file.</param>
        public GirderPluginWrapper(string fileName)
        {
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("Empty or null file name", "fileName");
            }

            if (!LoadGirderPlugin(fileName))
            {
                throw new InvalidOperationException(String.Format("Failed to load girder plugin ({0})", fileName));
            }

            int requiredApi = GirRequestedApi;

            if (requiredApi > GirMaxApi)
            {
                throw new InvalidOperationException(
                          String.Format("Failed to load girder plugin ({0}), plugin requires newer API version ({1})", fileName,
                                        requiredApi));
            }

            _apiFunctions                   = new GirApiFunctions();
            _apiFunctions.delete_var        = delete_var;
            _apiFunctions.get_double_var    = get_double_var;
            _apiFunctions.get_int_var       = get_int_var;
            _apiFunctions.get_link_name     = get_link_name;
            _apiFunctions.get_osd_font_name = get_osd_fontname;
            _apiFunctions.get_osd_settings  = get_osd_settings;
            _apiFunctions.get_string_var    = get_string_var;
            _apiFunctions.gir_free          = gir_free;
            _apiFunctions.gir_malloc        = gir_malloc;
            _apiFunctions.hide_osd          = hide_osd;
            _apiFunctions.i18n_translate    = i18n_translate;
            _apiFunctions.parse_reg_string  = parse_girder_reg;
            _apiFunctions.realloc_pchar     = realloc_pchar;
            _apiFunctions.register_cb       = register_cb;
            _apiFunctions.run_parser        = run_parser;
            _apiFunctions.send_event        = send_event;
            _apiFunctions.set_command       = set_command;
            _apiFunctions.set_double_var    = set_double_var;
            _apiFunctions.set_int_var       = set_int_var;
            _apiFunctions.set_string_var    = set_string_var;
            _apiFunctions.show_osd          = show_osd;
            _apiFunctions.start_osd_draw    = start_osd_draw;
            _apiFunctions.stop_osd_draw     = stop_osd_draw;
            _apiFunctions.target_enum       = target_enum;
            _apiFunctions.treepicker_show   = treepicker_show;
            _apiFunctions.trigger_command   = trigger_command;

            _apiFunctions.parent_hwnd = IntPtr.Zero;
            _apiFunctions.size        = Marshal.SizeOf(_apiFunctions);

            byte[] rawData = new byte[_apiFunctions.size];
            _apiFunctionsHandle = GCHandle.Alloc(rawData, GCHandleType.Pinned);
            _apiFunctionsPtr    = _apiFunctionsHandle.AddrOfPinnedObject();
            Marshal.StructureToPtr(_apiFunctions, _apiFunctionsPtr, false);
        }
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Dispose managed resources ...
            }

            // Free native resources ...
            if (_pluginDll != IntPtr.Zero)
            {
                FreeLibrary(_pluginDll);
            }

            if (_apiFunctionsHandle.IsAllocated)
            {
                _apiFunctionsHandle.Free();
            }

            _apiFunctions = new GirApiFunctions();
        }
    /// <summary>
    /// Releases unmanaged and - optionally - managed resources
    /// </summary>
    /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
    protected virtual void Dispose(bool disposing)
    {
      if (disposing)
      {
        // Dispose managed resources ...
      }

      // Free native resources ...
      if (_pluginDll != IntPtr.Zero)
        FreeLibrary(_pluginDll);

      if (_apiFunctionsHandle.IsAllocated)
        _apiFunctionsHandle.Free();

      _apiFunctions = new GirApiFunctions();
    }
    /// <summary>
    /// Initializes a new instance of the <see cref="GirderPluginWrapper"/> class.
    /// </summary>
    /// <param name="fileName">Name of the plugin dll file.</param>
    public GirderPluginWrapper(string fileName)
    {
      if (String.IsNullOrEmpty(fileName))
        throw new ArgumentException("Empty or null file name", "fileName");

      if (!LoadGirderPlugin(fileName))
        throw new InvalidOperationException(String.Format("Failed to load girder plugin ({0})", fileName));

      int requiredApi = GirRequestedApi;

      if (requiredApi > GirMaxApi)
        throw new InvalidOperationException(
          String.Format("Failed to load girder plugin ({0}), plugin requires newer API version ({1})", fileName,
                        requiredApi));

      _apiFunctions = new GirApiFunctions();
      _apiFunctions.delete_var = delete_var;
      _apiFunctions.get_double_var = get_double_var;
      _apiFunctions.get_int_var = get_int_var;
      _apiFunctions.get_link_name = get_link_name;
      _apiFunctions.get_osd_font_name = get_osd_fontname;
      _apiFunctions.get_osd_settings = get_osd_settings;
      _apiFunctions.get_string_var = get_string_var;
      _apiFunctions.gir_free = gir_free;
      _apiFunctions.gir_malloc = gir_malloc;
      _apiFunctions.hide_osd = hide_osd;
      _apiFunctions.i18n_translate = i18n_translate;
      _apiFunctions.parse_reg_string = parse_girder_reg;
      _apiFunctions.realloc_pchar = realloc_pchar;
      _apiFunctions.register_cb = register_cb;
      _apiFunctions.run_parser = run_parser;
      _apiFunctions.send_event = send_event;
      _apiFunctions.set_command = set_command;
      _apiFunctions.set_double_var = set_double_var;
      _apiFunctions.set_int_var = set_int_var;
      _apiFunctions.set_string_var = set_string_var;
      _apiFunctions.show_osd = show_osd;
      _apiFunctions.start_osd_draw = start_osd_draw;
      _apiFunctions.stop_osd_draw = stop_osd_draw;
      _apiFunctions.target_enum = target_enum;
      _apiFunctions.treepicker_show = treepicker_show;
      _apiFunctions.trigger_command = trigger_command;

      _apiFunctions.parent_hwnd = IntPtr.Zero;
      _apiFunctions.size = Marshal.SizeOf(_apiFunctions);

      byte[] rawData = new byte[_apiFunctions.size];
      _apiFunctionsHandle = GCHandle.Alloc(rawData, GCHandleType.Pinned);
      _apiFunctionsPtr = _apiFunctionsHandle.AddrOfPinnedObject();
      Marshal.StructureToPtr(_apiFunctions, _apiFunctionsPtr, false);
    }