# OpenPlugin

The OpenPlugin is called to create a new plugin instance.

    HANDLE WINAPI OpenPlugin(
      int OpenFrom,
      INT_PTR Item
    );

### Parameters

OpenFrom
Identifies how the plugin is invoked. Can be one of the following values (OPENPLUGIN_OPENFROM enum):

Constant | Description
--- | ---
OPEN_DISKMENU | Opened from the disks menu
OPEN_PLUGINSMENU | Opened from the plugins menu (`F11`)
OPEN_FINDLIST | Opened from the "Find File" dialog. The plugin will be called with this identifier only if it exports the SetFindList function, and SetFindList will be called only if OpenPlugin returns a valid handle.
OPEN_SHORTCUT | Opened using a folder shortcut command.
OPEN_COMMANDLINE | Opened from the command line.. This type is used if the plugin has defined a command prefix in the GetPluginInfo function, and this prefix, followed by a colon, is found in the command line.
OPEN_EDITOR | Opened from internal editor
OPEN_VIEWER | Opened from internal viewer.
OPEN_DIALOG | Opened from dialog

Item
Its meaning depends on the value of OpenFrom:

- For OPEN_DISKMENU, OPEN_PLUGINSMENU, OPEN_EDITOR and OPEN_VIEWER Item is a position of the activated plugin item in the exported items list in disks or plugins menu. If a plugin exports only one item, this field is always zero.
- For OPEN_FINDLIST Item is always zero.
- For OPEN_SHORTCUT Item contains the address of a string that was passed in the ShortcutData member of the OpenPluginInfo structure, when saving the shortcut. The plugin can use it to store any additional information about its current state. It is not necessary to save the information about the current directory, because it is restored by FAR when using folder shortcuts.
- For OPEN_DIALOG Item contains adress of an OpenDlgPluginData structure.
- For OPEN_COMMANDLINE Item contains address of a string containing the command line entered by the user. Plugin command prefix is not included in this string, unless the PF_FULLCMDLINE flag is set.
  For example, if a plugin defined the prefix ftp and the user entered `ftp://ftp.abc.com`, Item will point to `//ftp.abc.com`. However, if PF_FULLCMDLINE is set, Item will point to `ftp://ftp.abc.com`.

### Return value

If the function succeeds, the return value is a plugin handle. This handle will be passed later to other plugin functions to allow them to distinguish different plugin instances. Handle format is not important for FAR, it can be the address of a new plugin class object, or the address of a structure with plugin data, or an array index, or any other value but zero.

If the function fails, the return value must be `INVALID_HANDLE_VALUE.`

### Remarks

1. Note that you can use this function to implement FAR commands that work without creating new panels. Just perform all necessary actions here and return INVALID_HANDLE_VALUE.
2. If this functions returns zero, the plugin will be unloaded.