Page 1 of 1

[Advanced Topic] Programming DLL

Posted: Mar 30 2011
by TJ
TS EasyLanguage Extension Software Development Kit (SDK)
provides users with the ability to write code in a programming language that allows for the creation of DLLs (for example, C++, Pascal, Delphi, or Visual Basic) and call that code from within an EasyLanguage analysis technique.

https://www.multicharts.com/trading-sof ... on_Sources

Category: DLL Calling
https://www.multicharts.com/trading-sof ... LL_Calling


see also:
[Advanced Topic] MultiCharts 64 bit Resources
viewtopic.php?f=16&t=10094


PS. If you search using the keywords [Advanced Topic] or DLL, you will find additional useful posts
eg. search.php?keywords=dll&terms=all&autho ... ulticharts



-------------------------------------------------------
Has this post been helpful to you?

[Advanced Topic] MultiCharts -- Programming DLL

Posted: Apr 21 2011
by power
Hi,

Is MultiCharts has a sdk to develop using C#. I want to use Visual Studio and build .dll files than import to MultiCharts. Is there a mechanism like that in Wealth-Lab.

Re: MultiCharts using C#

Posted: Apr 21 2011
by Stan Bokov
MultiCharts can use external DLL files from PowerLanguage script. You can use the following keywords to access external DLLs:

external method: "myfile.dll"

However, keep in mind that PLE is available only the regular version of MultiCharts.

Re: MultiCharts using C#

Posted: Feb 29 2012
by arjfca
MultiCharts can use external DLL files from PowerLanguage script. You can use the following keywords to access external DLLs:

external method: "myfile.dll"

However, keep in mind that PLE is available only the regular version of MultiCharts.
Stan,

Under witch directory does the dll file need to reside? I got problem to access special dll functions

Martin

Re: MultiCharts using C#

Posted: Mar 01 2012
by Henry MultiСharts
Hello Martin,

If you do not specify the path to the dll then the script will search for it in the MultiCharts folder

32 bit: C:\Program Files (x86)\TS Support\MultiCharts
64 bit: C:\Program Files\TS Support\MultiCharts64

If you specify the path to the dll then the script will search for it in the specified folder.

Re: MultiCharts using C#

Posted: Mar 01 2012
by JoshM
Is MultiCharts has a sdk to develop using C#.
MultiCharts can use external DLL files from PowerLanguage script.
If I'm not mistaken, MultiCharts can not work with C# DLL's? (C++ works, and the EL and ADE are also written in this if I recall correctly)

I'm wondering because I could not make C# DLL's to work with MultiCharts, and was advised by support to use C++ code for what I was trying to achieve.

I know more C# than C++, hence my question. :)

Re: MultiCharts using C#

Posted: Mar 02 2012
by Henry MultiСharts
You can make C# DLLs to work in MultiCharts.
You can find more information regarding the subject in
TS EasyLanguage Extension Software Development Kit.

You can also submit a feature request to the Project Management: "use .NET assemblies from PowerLanguage" with detailed explanation how do you want to use it.

Writing DLLs for MC64

Posted: Mar 05 2012
by trader39
https://developer.TS.com/docu ... on_SDK.pdf

indicates that tskit.dll should be imported to write dlls. However that is a 32 bit dll, which presumably is incompatible with MC64. Do you have a tskit.dll substitute for writing 64 bit dlls, or alternatively, suggestions on how to write DLLs without tskit?

Re: Writing DLLs for MC64

Posted: Mar 06 2012
by Henry MultiСharts
Hello Trader39,

You need to use PLkit.dll to write 64 bit DLLs.
This dll can be found in MultiCharts folder.




moderator's note:
[Advanced Topic] MultiCharts 64 bit Resources
viewtopic.php?f=16&t=10094

Re: Writing DLLs for MC64

Posted: Mar 06 2012
by trader39
Great.

What (preferably free and available online) compiler (Java or C or C++) would you recommend to write MC64 compatible dlls? I presume a 64 bit compiler is required, but I note that cc1plus.exe *32 (presumably 32 bit?) is active in the task manager when MC64 power language scripts are compiled.

Re: Writing DLLs for MC64

Posted: Mar 06 2012
by trader39
I note that Visual Studio 2010 is available for free 30 day trial download so that would be an option, if you recommend it, although it does not seem to support Java. (Please advise whether to run it in 32 or 64 bit mode if you do recommend it).

Re: Writing DLLs for MC64

Posted: Mar 12 2012
by Dave Masalov
Hi
VS DLL are not compatible with MC.
Emmanuel
VS DLL are compatible with MultiCharts. Please use Microsoft Visual Studio 2008 or 2010 C++

For MC 64 bit compile dll for x64 platform.
For MC 32 bit compile dll for Win32 platform.

Re: Writing DLLs for MC64

Posted: Mar 12 2012
by Dave Masalov
What (preferably free and available online) compiler (Java or C or C++) would you recommend to write MC64 compatible dlls? I presume a 64 bit compiler is required, but I note that cc1plus.exe *32 (presumably 32 bit?) is active in the task manager when MC64 power language scripts are compiled.
So what compiler do you recommend?
Basically, you can use any software that you are familiar with as long as it compiles Win32 and x64 dlls.

See more discussions here:
viewtopic.php?f=1&t=8391&p=39052&hilit=DLLS#p39052

Re: MultiCharts using C#

Posted: Jun 22 2012
by JoshM
You can make C# DLLs to work in MultiCharts. You can find more information regarding the subject in TS EasyLanguage Extension Software Development Kit.
Can you explain how to make a C# dll? I've followed the EasyLanguage Extension SDK to the letter, but run into problems with step 1: importation of tskit.dll (which I don't have). If I add the elkit32.dll from the MultiCharts program folder as a reference to the Visual Studio DLL, I get the
Could not load file or assembly 'elkit32.dll' or one of it dependencies. The module was expected to contain an assembly manifest.

This file may not be a managed assembly.
error message. If I try to import it as an unmanaged assembly (through DLLImport), I don't know how to make the accompanying method/entry point, since well, I can't look into that DLL for the correct method name.

If I go ahead and make the DLL without the elkit32.dll reference, I get the "can't find function .. in dll" error message when adding the indicator.

So to summarize; does someone has a working C# project (that can be reverse engineered to learn how it works), or willing/able to write down the needed steps? :)

Re: MultiCharts using C#

Posted: Jun 27 2012
by Dru
So to summarize; does someone has a working C# project (that can be reverse engineered to learn how it works), or willing/able to write down the needed steps? :)
The question like "How I can use .NET assembly in MultiCharts (PL)" is same as question "How I can use .NET assembly in any unmanaged application". There are many ways exists.

PL code for example:

Code: Select all

EXTERNAL: "net_assembly_interop.dll", double, "Summ", double, double;
if close + open <> Summ(close, open) then raiseruntimeerror(":-(");

Re: MultiCharts using C#

Posted: Jun 27 2012
by JoshM
Thanks Dru for your example! :)

If you allow me another newbie question, can you (or someone else) tell how to use this generated DLL in MultiCharts from the VS project? Here's what I've done:

1) Opened the project file Call_dotNET_code_from_PL in Visual Studio,
2) Visual Studio converted both projects to VS10 project format,
3) Hit F6 to build solution,
4) Copied the net_assembly_interop.dll file from '\Call_dotNET_code_from_PL\Debug\' to 'C:\Program Files\MultiCharts\'.
5) Added the following PowerLanguage code in an empty indicator:

Code: Select all

EXTERNAL: "net_assembly_interop.dll", double, "Summ", double, double;

if (LastBarOnChart_s = True) then begin

Print("10 + 231.2 = ", Summ(10, 231.2));

end;
6) Got an application error after adding the indicator to the chart.
Image

If I use the net_assembly.dll, I get the "Can't find function 'Summ' in dll." error message.

Re: MultiCharts using C#

Posted: Jun 28 2012
by Dru
4) Copied the net_assembly_interop.dll file from '\Call_dotNET_code_from_PL\Debug\' to 'C:\Program Files\MultiCharts\'.
net_assembly_interop.dll is the C++/CLI "mixed" dll (native dll + managed code). i.e. it is PROXY that delegate all work to net_assembly.dll - is the pure managed dll (assembly) that do all job.
You need copy both dll to MC dir
P.S. During build take attention to Solution Configuration and MultiCharts.exe bit depth (x64 vs x86)

Re: MultiCharts using C#

Posted: Oct 28 2012
by alanyangbo
4) Copied the net_assembly_interop.dll file from '\Call_dotNET_code_from_PL\Debug\' to 'C:\Program Files\MultiCharts\'.
net_assembly_interop.dll is the C++/CLI "mixed" dll (native dll + managed code). i.e. it is PROXY that delegate all work to net_assembly.dll - is the pure managed dll (assembly) that do all job.
You need copy both dll to MC dir
P.S. During build take attention to Solution Configuration and MultiCharts.exe bit depth (x64 vs x86)
good job! Another question:if c# function return String and its parameters also string,then how to correct write c++ dll?It is big problems for me :( Looking forward to your reply!
Alan.

Re: MultiCharts using C#

Posted: Oct 29 2012
by Henry MultiСharts
Another question:if c# function return String and its parameters also string,then how to correct write c++ dll?It is big problems for me :( Looking forward to your reply!
Alan.
Here is how you need to define the functions that should receive the strings in C++/CLI dll:

Code: Select all

System::String ^ __clrcall TestString(System::String ^ s1)
Here is how such function should be described in PLE:

Code: Select all

DefineDLLFunc: "net_assembly_interop.dll", string, "TestString", string;

Re: [Advanced Topic] Programming DLL

Posted: Nov 21 2012
by beolee
my c++ source MyDllFile.cpp:

Code: Select all

#import "D:\Prog\TS Support\MultiCharts\tskit.dll" no_namespace
#include <atlbase.h>

//////////////////////////////////////////////////////////////
// Calculate simple moving average value

double __stdcall MovAvg
( IEasyLanguageObject * pELObj, int iAvgLength )
{
double dMovAvg ;
dMovAvg = 0 ;

// verify that sufficient bars have passed before back-referencing historical prices
//if( pELObj->CloseMD[data1]->BarsBack > iAvgLength && iAvgLength > 0 )

{
double dSum = 0.0 ;
for (int i = 0; i < iAvgLength; i++)
{
dSum += pELObj->CloseMD[data1]->AsDouble[ i ] ;
}
dMovAvg = dSum / iAvgLength ;
}
//return dMovAvg ;
return 1.1;
}

//////////////////////////////////////////////////////////////
// Generate a run-time error in TS
// This function is called internally by other DLL functions when an error in TS
// is to be produced.

void fnGenRunTimeError
( IEasyLanguageObject * pEL, int iErrorNum )
{
TSRuntimeErrorItem tsItem;
int m_HistErr ;
tsItem.sCompany = _bstr_t("TS Securities, Inc.").copy();
tsItem.sErrorLocation = _bstr_t("Example Code Library").copy();
tsItem.sErrorCategory = _bstr_t("Error").copy();
tsItem.sLongString = NULL;
tsItem.nParameters = 0;

switch ( iErrorNum )
{
case 1:
{
// Error 1
tsItem.sShortString = _bstr_t("Error – Description of Error 1 goes here.").copy();
tsItem.sSourceString = _bstr_t("Additional detailed description goes here.").copy();
tsItem.nErrorCode = iErrorNum ;
}
break ;
case 2:
{
// Error 2
tsItem.sShortString = _bstr_t("Error – Description of Error 2 goes here.").copy();
tsItem.sSourceString = _bstr_t("Additional detailed description goes here.").copy();
tsItem.nErrorCode = iErrorNum ;
}
break ;
default:
{
// Generate a run-time error of undefined type or origin
tsItem.sShortString = _bstr_t("Undefined error in "
"MyDLL.dll.").copy();
tsItem.sSourceString = _bstr_t("Error origin undefined.").copy();
tsItem.nErrorCode = 9999 ;
}
}

m_HistErr = pEL->Errors->RegisterError( &tsItem ) ;
pEL->Errors->RaiseRuntimeError( m_HistErr ) ;
}


//////////////////////////////////////////////////////////////
// Server field call
double __stdcall GETSERVERFIELD
(IEasyLanguageObject *pEL, LPSTR szFName)
{
// IEasyLanguageServerField *iSF = pEL->ServerField[_bstr_t(szFName)][dataDefault];
// return iSF->AsDouble[0];
return 1.0;
}


//////////////////////////////////////////////////////////////
// Sort an EasyLanguage array using this DLL function

void __stdcall MYARRAYSORT
( IEasyLanguageObject* pELObj, char* MyArrayName )
{
int nOuter, nInner ;
IEasyLanguageVariable* pELVar = pELObj->Variables[ MyArrayName ] ;
if ( pELVar->Dimensions == 1 )
{
int nSize = pELVar->DimensionSize[0] ;
for ( nOuter = 0; nOuter < nSize - 1; nOuter++ )
{
for ( nInner = nOuter + 1; nInner < nSize; nInner++ )
{
pELVar->SelectedIndex[0] = nInner ;
double dSecondValue = pELVar->Value[0] ;
pELVar->SelectedIndex[0] = nOuter ;
double dFirstValue = pELVar->Value[0] ;
if ( dSecondValue < dFirstValue )
{
double dTmp = dFirstValue ;
pELVar->Value[0] = dSecondValue ;
pELVar->SelectedIndex[0] = nInner ;
pELVar->Value[0] = dTmp ;
}
}
}
}
}


//////////////////////////////////////////////////////////////
// Fill dynamic EasyLanguage array

void __stdcall FILLDYNARRAY
(IEasyLanguageObject * pEL, LPSTR PassedVar)
{
IEasyLanguageVariablePtr pMyVar = NULL;
IELFrameworkArrayPtr pDynArray = NULL;

IEasyLanguageDateTime * pMyDateTime = pEL->DateTimeMD[ dataDefault ] ;
double myDT = pMyDateTime->AsDateTime [0] ;

long nTotVars = pEL->VariablesCount;
for (long n = 0; n < nTotVars; n++)
{
pMyVar = pEL->Variables[n];
_bstr_t mybstr = pMyVar->Name;
if (pMyVar->DataType == dtHandle)
{
int nValue = pMyVar->GetAsInteger(0);
CComVariant xx(pEL->Close[0]);
if (pEL->System->Array->IsValidHandle( (int) nValue ) && (mybstr == (_bstr_t) PassedVar))
{
pDynArray = pEL->System->Array;
pDynArray->SetValue(nValue, 0, CComVariant(xx));
}
}
}
}
//////////////////////////////////////////////////////////////
// Sum upticks and downticks from intraday chart to get volume in DLL – store in global DLL variable

double dMyDLLDouble = 0; //global variable

int __stdcall SetdMyDLLDouble
( IEasyLanguageObject * ELObjP )
{
dMyDLLDouble = ELObjP->UpTicksMD[dataDefault]->AsDouble[0]
+ ELObjP->DownTicksMD[dataDefault]->AsDouble[0] ;
return 1;
}
===============================
my pl source :

Code: Select all

external: "MyDllFile.dll", double, "MovAvg", IEasyLanguageObject {self}, int {Length};

inputs:
Length( 10 ) ;

variables:
double MyELVar( 0 ) ;

MyELVar = MovAvg( self, Length ) ;

plot1(MyELVar ,"MyELVar ");
======================================
when I add the indicator to the chart , I got a error message cannot find the "MovAvg" function.

I have copied the MyDllFile.dll into MultiCharts directory.

Can you help me?

Re: [Advanced Topic] Programming DLL

Posted: Nov 21 2012
by Henry MultiСharts
beolee, the function is not defined as external in your dll.
You need to define it as an external function or create a def file in VS and add this function to it.

Re: MultiCharts using C#

Posted: Jan 21 2013
by Dru
if c# function return String and its parameters also string,then how to correct write c++ dll?
Example updated.

Code: Select all

EXTERNAL: "net_assembly_interop.dll", lpstr, "ReturnStringExample", lpstr;
plot1( ReturnStringExample("from PL") );

Re: MultiCharts using C#

Posted: Jan 25 2013
by JoshM
if c# function return String and its parameters also string,then how to correct write c++ dll?
Example updated.

Code: Select all

EXTERNAL: "net_assembly_interop.dll", lpstr, "ReturnStringExample", lpstr;
plot1( ReturnStringExample("from PL") );
Dru, can you tell something about how you created the net_assembly_interop C++ dll? That way I can create another DLL with a different name. I know practically nothing about C++, so if it's not to much to ask, can you say, in "Dummy language" which steps you took?

(Edit: Since the PowerLanguage code calls the interop dll, I assume that every C# dll need its own accompanying interop dll, hence the question. Don't know though if this assumption is valid.)

Re: MultiCharts using C#

Posted: Feb 26 2013
by Dru
Dru, can you tell something about how you created the net_assembly_interop C++ dll?
Hmm ...
Do you want to know how I am writing a program in C++? :)
You can take the example and change project properties for new dll name.
Keywords for studying: C++/CLI, MS VS 2008, export functions from dll

Re: MultiCharts using C#

Posted: Feb 26 2013
by Dru
Since the PowerLanguage code calls the interop dll, I assume that every C# dll need its own accompanying interop dll, hence the question. Don't know though if this assumption is valid.)
This is not necessary. The ONE interop dll can be the "bridge" for many .NET (C#) assemblies.

Re: [Advanced Topic] Programming DLL

Posted: Mar 12 2013
by csharpstudent
Hello all.
I have tried to follow the very helpful responses above on how to build a dll for MC.

I would REEEEALLLY be thankfyl if anyone could help me get the following accomplished:

Objective of the DLL - Send from PowerLanguage code, date and time and read an ASCII file and pass the value back to MC 32 bit.

Format of file

1/1/2012 12:04 565.6
1/1/2012 12:05 675.4

Format is
<dd/mm/yyyy> <hh:mm> <numeric value>

So I would send the date and time into the DLL via PowerLanguage and receive back the value.

I would via this exercise love to learn how to write DLLs to be used, so some clarity on how to integrate it into MC 32 bit (and eventually MC64).

I really look forward to your help.

Best Reagrds

Re: [Advanced Topic] Programming DLL

Posted: Mar 13 2013
by arjfca
Hello all.
I have tried to follow the very helpful responses above on how to build a dll for MC.

I would REEEEALLLY be thankfyl if anyone could help me get the following accomplished:

Objective of the DLL - Send from PowerLanguage code, date and time and read an ASCII file and pass the value back to MC 32 bit.

Format of file

1/1/2012 12:04 565.6
1/1/2012 12:05 675.4

Format is
<dd/mm/yyyy> <hh:mm> <numeric value>

So I would send the date and time into the DLL via PowerLanguage and receive back the value.

I would via this exercise love to learn how to write DLLs to be used, so some clarity on how to integrate it into MC 32 bit (and eventually MC64).

I really look forward to your help.

Best Reagrds
Not answering your question but,
If I remenber, there is ElCollection.dll that could read/write asci file.

Martin

Re: [Advanced Topic] Programming DLL

Posted: Mar 13 2013
by csharpstudent
Martin,
Thanx for the pointer. Where would I find this ElCollection.dll , its docs/usage steps etc.

Best

Re: [Advanced Topic] Programming DLL

Posted: Mar 13 2013
by youn56

Re: [Advanced Topic] Programming DLL

Posted: Mar 13 2013
by arjfca
Martin,
Thanx for the pointer. Where would I find this ElCollection.dll , its docs/usage steps etc.

Best
CsharpStudent. Look on this post from user TJ: viewtopic.php?f=16&t=10094#p48319


Martin :)

Re: [Advanced Topic] Programming DLL

Posted: Jan 25 2014
by eto
Hi,

I'm sorry. Seems i'm a bit late of discussing about C# dll called in Easylanguage.

Hope someone still can help me because a bit confuse after reading the topic from above. I have downloaded dru's example but doesn't look like in example in TS sample which is using c/c++.

I'm using MC 64 bit. Do i still need to import PLkit.dll in creating C# dll or i do not need to import PLkit.dll ? Appreciate someone explain further details or step by step.

Thanks.

Re: [Advanced Topic] Programming DLL

Posted: Oct 21 2014
by Richardo
Hi,

Is MultiCharts has a sdk to develop using C#. I want to use Visual Studio and build .dll files than import to MultiCharts. Is there a mechanism like that in Wealth-Lab.

Re: [Advanced Topic] Programming DLL

Posted: Oct 21 2014
by Henry MultiСharts
Hello Richardo,

Please check the Extension Software Development Kit at Additional Information Sources page.

Re: [Advanced Topic] Programming DLL

Posted: Feb 24 2016
by leverman
Hello,

some time passed for this topic and I think the new VS version is causing me problems.

When Multicharts64 uses an indicator that has the external-keyword in order to call a c++ dll I get the “Can’t find Dll “<myDll>.dll””- message. I was able to use predefined .dlls that are shipped with MC64 in the PLEditor (like GlobalVariable.dll). On the other hand when ever I try to add a reference to my VS 2015 Project it says that the library is either not a .net assembly, build in a higher version of .net or is not a registered ActiveX control. It seems that there has been an update to the VS built-in compiler that makes unreadable builds for MC64. My basic goal is to use c# dlls in powerlanguage. Using MC .net is not an option...yet. So what are the specific setups for building for example the GlobalVariable.dll?

I used the code that was provided in this thread by Dru.

Re: [Advanced Topic] Programming DLL

Posted: Sep 18 2018
by Smoky
@ Dru

please can You update our sample "Call_dotNET_code_from_PL.zip" projet , i use VS 17 and i have many errors.

Thanks

Re: MultiCharts using C#

Posted: Nov 29 2018
by andrei
if c# function return String and its parameters also string,then how to correct write c++ dll?
Example updated.

Code: Select all

EXTERNAL: "net_assembly_interop.dll", lpstr, "ReturnStringExample", lpstr;
plot1( ReturnStringExample("from PL") );
Dru, can you tell something about how you created the net_assembly_interop C++ dll? That way I can create another DLL with a different name. I know practically nothing about C++, so if it's not to much to ask, can you say, in "Dummy language" which steps you took?

(Edit: Since the PowerLanguage code calls the interop dll, I assume that every C# dll need its own accompanying interop dll, hence the question. Don't know though if this assumption is valid.)
do you need to use the same external statement to import GlobalVariable.DLL present in the MC64 install folder?

thx

Re: [Advanced Topic] Programming DLL

Posted: Nov 29 2018
by Smoky
no andrei, GlobalVariables are in standard in MC? You don't have to define functions.
Global Variable 2.2.doc
(336.5 KiB) Downloaded 394 times

Re: [Advanced Topic] Programming DLL

Posted: Dec 11 2018
by kh_model
When it is stated that PLKit.dll is required to build a dll which works with Multicharts64, should I assume that even a dll which does not make use of any internal MultiCharts or Powerlanguage functions must be built against PLKit.dll if I wish to call it from within PowerLanguage? Using a tool like Depends.exe, I can never seem to find any references to PLKit.dll when I examine existing known 64 bit dlls such as ELTicToc.dll. In fact, I see no references to ELKit.dll or TSKit.dll when I examine with Depends.exe any third party dlls which are known to be 32 bit implementations and which are also known to work with MultiCharts and TS. Does that mean that those dlls were not built against any kind of sdk which relates to TS or Multicharts? I would like to see an old example in C or C++ in which getProcAddress is used to load a third party dll function so that I can have a better idea of how that would be applied to MultiCharts64 without using C# or managed code.

The first part of my question has been answered on pages 2-3 in the document called: EasyLanguage-Extension-SDK.pdf which seems to be a secure document that prevents me from easily copying and pasting its content so I will simply refer the reader to it.

The second part of my question is answered by a thread at experts exchange, but the code is a bit fragmented. Here is a link to that discussion:
https://www.experts-exchange.com/questi ... ction.html

I was hoping to find a specific example in C or C++ which focuses on using GetProcAddress to load a function from the Swiss Ephemeris swedll32.dll or swedll64.dll as part of a custom dll wrapper for use in MultiCharts but so far I have not discovered one.