// The top of every source code file must include this line
#include "sierrachart.h"
#include <iostream> 

/*****************************************************************************

	This file contains Sierra Chart custom study template functions and example functions.
	
	For reference, refer to the Advanced Custom Study Interface
	and Language documentation on the Sierra Chart website:
    http://www.sierrachart.com/index.php?page=doc/AdvancedCustomStudyInterfaceAndLanguage.php
	
*****************************************************************************/


// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies. 
SCDLLName("Call External DLL") 

typedef int(*AddFunc)(int, int);
typedef void(*FunctionFunc)();

AddFunc _AddFunc;
FunctionFunc _FunctionFunc;
HINSTANCE hInstLibrary = LoadLibrary("DLL_Tutorial.dll");
int a = 10;

//This is the basic framework of a study function.
SCSFExport scsf_SkeletonFunction(SCStudyGraphRef sc)
{
	// Set the configuration variables and defaults

	if (sc.SetDefaults)
	{
		
		sc.GraphName = "Skeleton Function";
		
		sc.AutoLoop = 1;  // Automatic looping is enabled.
		
		// During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart. When development is completed, set it to 0 to improve performance.
		sc.FreeDLL = 1; 

		sc.Subgraph[0].Name = "Subgraph 1 Name";
		sc.Subgraph[0].PrimaryColor = RGB(255,0,0);  // Red
		sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;  // Look in scconstants.h for other draw styles
		
		sc.Input[0].Name = "Input 1 Name";
		sc.Input[0].SetInt(20);  // Set the default value to 20
		sc.Input[0].SetIntLimits(1, 1000);  //Optional:  Limit the range of this input to 1-1000
		
		return;
	}
	
	
	// Data processing

	// Fill in the first subgraph output data array.  Modify this line to do what you want. This line simply will make this study draw a line at the value of 1 .



	if (hInstLibrary)
	{
		_AddFunc = (AddFunc)GetProcAddress(hInstLibrary, "Add");
		_FunctionFunc = (FunctionFunc)GetProcAddress(hInstLibrary,
			"Function");

		if (_AddFunc)
		{
			std::cout << "23 + 43 = " << _AddFunc(23, 43) << std::endl;
			a = _AddFunc(20, 20);
		}
		if (_FunctionFunc)
		{
			_FunctionFunc();
		}

		FreeLibrary(hInstLibrary);
	}
	else
	{
		std::cout << "DLL Failed To Load!" << std::endl;
	}

	sc.Subgraph[0][sc.Index] = a;

}