library InputSDKExample;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes,
  Windows,
  Commctrl;

{$R *.res}

var
  SomeTextOutput : String;
  Samurize       : HWND;

// dllstartup() is called every time Samurize creates a meter that uses this plugin.
// The 'hwnd' parameter is the window handle of the instance of Samurize that called this function.
// 'hwnd' will be 0 if called from the config editor.
// The 'dlltype' parameter indicates the meter 'type' (1 for source plugins, 2 for visual plugins)
// that is currently initialized.
// This function should return a unique integer ID that Samurize remembers and uses for other functions
// (this is so multiple instances of Samurize that use this do not conflict).
//
// Any memory allocation needed on a meter-by-meter basis should be done in this function.
//
// If your plugin is very simple and does not need to keep any global variables that may cause conflicts,
// just return 0 (or omit this function).
function dllStartup(hwnd : HWND; dlltype : Integer):Integer;stdcall;
begin
  //This example has an if statement to work out which parameters to initialise
  //Type 1 is the source plugin section and that returns an integer and setups
  //the SomeTextOutput (A global variable)
  if dlltype = 1 then begin
    Result := 234234234;
    SomeTextOutput := 'InputTest';
  end else if dlltype = 4 then begin
    //Type 4 is the Input SDK type and this allocates the samurize HWND and
    //also returns a number.  NB: the numbers returned should be unique this
    //plugin will only run once happy with one instance of it.
    Samurize := hwnd;
    Result := 19;
  end;
end;

// dllshutdown() is called every time a meter is destroyed by Samurize.
// The 'id' parameter is the uniqueID your plugin assigned to the meter (returned by dllstartup)
// This function should always return 0.
//
// Any memory releasing needed on a meter-by-meter basis should be done in this function.
//
// If your plugin does not need to free any memory, this function may be omitted.
function dllShutdown(id : Integer):Integer;stdcall;
begin
  Result := 0;
end;

function Init():PChar;stdcall;
begin
	// ok here you will return the list of the functions, separated by 
	// a | if there are more than one like
	// that somefunc|someotherfunc|alastfunc
  Result:= 'TestFunction';
end;

//Samurize GetParam, returns a list of the parameters that each function needs
Function GetParam(func: PChar):PChar;stdcall;
begin
	//here you should have an if statement or a case to determnie what was function asking for params
	//the func param is the config editor asking for the parameter list of a funcion
	//so return the tex separated by | and this time it must finish with a |
	//ie : param1|param2|
	//or must be empty like in this template when there are no parameters
  Result := '';
end;

// getinfo() should return information about your plugin depending on the passed integer value.
// 0: Plugin name
// 1: Author name
// 2: Plugin version
// 3: Creation date
// 4: Last modified date
// 5: Website
// 6: Contact email address
//
// This information is displayed when the 'About' button is pressed in the config editor when your plugin
// is selected.
//
// This function is optional.
function GetInfo(infonum : Integer):PChar;stdcall;
begin
	//called by samurize to display something useful in the about dialog.
	case infonum of
        0: result := 'Input SDK Sample Version 1';
        1: result := 'AdamC';
        2: result := '1.0.0.0';
        3: result := '09/02/05';
        4: result := '09/02/05';
        5: result := 'http://www.adamcoulthard.co.uk';
        6: result := 'adamc@samurize.com';
        else result := ''
  end;
end;

// DLLType: Tells Samurize what type of plugin this is.
// because this dlltype() function is declared, Samurize will assume you are using the SDK v2.0;
// 	* All functions will be called with an additional first parameter, the meter's unique_id
//
// Omit the dlltype() function to use the old SDK (the uniqueID will be omitted)
//
// The value you should return is a summation of any or all of the following values:
// 1: Source plugin
// 2: Visual plugin
// 4: Input plugin
function dllType():Integer;stdcall;
begin
  result := 5;
	// you can also have a source plugin and a visual plugin in the same dll,
	// if so, return the sum of the plugin type numbers (that would be 3)
end;

//Standard Source function, returns an text value back to samurize for display
function TestFunction(id : Integer):PChar;stdcall;
begin
  Result := PChar(SomeTextOutput);
end;

//ActionsProvided method
function ActionsProvided():PChar;stdcall;
begin
  //This method should return a string which contains the list of actions that you
  //support in your plugin.  If you dont return the list them samurize will not call
  //your plugin. (This method is similar to the init and GetParam methods)
  //This ActionsProvided returns a value of
  //
  //5001|5002|5010|5011|5020|
  Result := PChar(IntToStr(5001) + '|' + IntToStr(5002) + '|' + IntToStr(5010) + '|' + IntToStr(5011) + '|' + IntToStr(5020) + '|');
end;
//action() is called when ever an action occurs for example left click.
//Your plugin can cope with all the actions or a subset of actions.  However
//your plugin must not assume that the user has assigned it to the correct
//action, and should perform a check before processing the command.

//Parameters:
//id - the unique ID assigned to the meter by the dllstartup() function
//action - this is an integer representing the action that has occurred, samurize
//         online help for the full list of actions
//sourcepluginid - id of the plugin source associated with this meter, 0 if no meter is associated</li>
//outputpluginid - id of the plugin output associated with this meter, 0 if no meter is associated</li>
//X              - X location of the mouse click
//Y              - Y Location of the mouse click
//left           - Meter Location value - Left
//top            - Meter Location value - Top
//right          - Meter Location value - Right
//bottom         - Meter Location value - Bottom
//files - This is only used when a 5020 action occurs, it provides the plugin
//        with a list of file names separated by a |
function Action(id : Integer; Action : Integer; SourceUniqueID : Integer; OutputUniqueID : Integer; X : Integer; Y : Integer; left : Integer; top : Integer; right : Integer; bottom : Integer; Files : PChar) : Integer;stdcall;
begin
  //Left Mouse Click
  if Action = 5001 then begin
    SomeTextOutput := 'Left Mouse was clicked X is ' + IntToStr(X) + ' Y is ' + IntToStr(Y);
  //Right Mouse Click
  end else if Action = 5002 then begin
    SomeTextOutput := 'Right Mouse was clicked X is ' + IntToStr(X) + ' Y is ' + IntToStr(Y);
  //Mouse over Action
  end else if Action = 5010 then begin
    SomeTextOutput := 'Mouse over - MeterName is ' + IntToStr(SourceUniqueID);
  //Mouse out Action
  end else if Action = 5011 then begin
    SomeTextOutput := 'Mouse out - MeterName is ' + IntToStr(SourceUniqueID);
  //Drag and Drop Action
  end else if Action = 5020 then begin
    SomeTextOutput := files;
  //No action catch just incase more actions are added and your plugin does get
  //called by accident.
  end else begin
    SomeTextOutput := 'Action not known';
  end;

  //Always return 0
  Result := 0;
end;

//Export the functions of the dll so that samurize can access them
exports dllStartup name 'dllstartup';
exports dllShutdown name 'dllshutdown';
exports ActionsProvided name 'actionsprovided';
exports Action name 'action';
exports init name 'init';
exports getparam name 'getparam';
exports TestFunction name 'TestFunction';
exports dlltype name 'dlltype';

begin
end.
