Calling DLL Example

Author: Optuma Team Last updated: Mar 2, 2021 20:04

This is the C source code to build the dll for Optuma to process the data list. The dll is called matool.dll.

#include <stdio.h>
#include <math.h>
// datain and dataout are two dimensional arrays with the following columns
#define DBDATE 0
#define DBCLOSE 1
#define DBHIDDEN 2
#define DBHIGH 3
#define DBLOW 4
#define DBOPEN 5
#define DBVOLUME 6
#define DBOI 7
#define DBBARTYPE 8
#define DBHIGHTIME 9
#define DBLOWTIME 10
#define DBFACTOR 11
#define DBCOLOUR 12
#define UnixStartDate 25569.0
// Converts MA DateTime to Unix seconds
// dtDate = the Date and Time that you want to convert
// returns the number of seconds since UTC 1 January 1970
long DateTimeToUnix(double dtDate)
{
   return lround((dtDate - UnixStartDate) * 86400);
};
extern "C"
{
   // datain and dataout are two dimensional arrays of double - both are the same size
   // this example simply adds 10 to the close of the data in.
   __declspec(dllexport) void processdata(double **datain, double **dataout, int count)
   {
       int i;
       for (i = 0; i<count are="" as="" case="" columns="" dataout="" i="" in="" left="" other="" pre="" the="" this="" zero="">
<br></br>
<span style="font-family:Verdana">This is the custom code source code in Optuma Custom tool to load and use the dll to process the data list.</span><br></br>
<br></br>
<br></br>
<br></br>
   <br></br>
//
// Sample script for Optuma tool programming using a C dll to process the data list.
//
// This section is where variable are defined that need to be used in both the Init and Process procedures
var
   Plot1 : TPlot;
// declare the procedure from the dll used to process the data list.
procedure processdata(datain, dataout: pointer; count: Integer); stdcall; external 'matool.dll' name 'processdata';
// DefineTool is where the settings for the Tool are defined
// This procedure is called once when the tool is loaded
// Normally this procedure does not need to be changed
procedure DefineTool(Tool : TTool);
begin
   Tool.Name := 'dllprocess';
   Tool.MouseClicks := 1;
   Tool.Hint := '';
   Tool.ToolType := ttDataList;
end;
// Init is called to initialise the tool
// This procedure is called once when the tool is added to a chart
procedure Init(Tool : TTool);
begin
   Plot1 := Tool.AddPlot();
   Plot1.Color := clBlue;
   Plot1.PlotStyle := Line; // possible values are (Line, Dot, Histogram, Stepped, Shaded)
   Plot1.FillColor := clBlue;
   Plot1.LineStyle := Dash;
end;
// Process is called to calculate and drawn the tool on screen
// This procedure is called when new data is received or loaded and
// when a selection point is moved by the user
procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
begin
   Plot1.Data.SetSize(datain.Count); // set the output plot the same size as the input data
   processdata(DataIn.DataArray, Plot1.Data.DataArray, Plot1.Count); // pass the data to the c dll
end;

</count></math.h></stdio.h>

Discussion