Calling external DLL from EasyLanguage - EasyLanguage Programming | futures io social day trading
futures io futures trading


Calling external DLL from EasyLanguage
Updated: Views / Replies:13,187 / 11
Created: by Big Mike Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Calling external DLL from EasyLanguage

  #1 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,353 given, 83,234 received


ehlaban View Post
Could somebody point me to some good description/tutorial/explanation on how to call an external DLL from Multicharts or Easylanguage if that's no different.

Ernesto

This example is for Visual Studio C++

Courtesy user wegi from MultiCharts forum:
TS SUPPORT :: View topic - Request : dll example

VS: New - Project - Win32 DLL

 
Code
                            
extern "C" LPCSTR __declspecdllexport __stdcall intToAsc(int v

 
   try{ 
 
      
char buffer [255]; 
      
sprintf (buffer,"%c"v); 
 
      return 
buffer
 
   } 
   catch(...){ 
      
LPCSTR sValue "ERR EXCEPTION"
        return 
sValue
   } 
 

Then create a DEF file to declare the functions exported:

 
Code
                            
EXPORTS    intToAsc 

Then use this EasyLanguage code:

 
Code
                            

vars
tab(""); 
 
DefineDLLFunc"dlltest.dll",  lpstr"intToAsc"int
 
if 
tab "" then tab intToAsc(9); 
Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following 3 users say Thank You to Big Mike for this post:
 
  #2 (permalink)
Elite Member
Chicago IL
 
Futures Experience: Intermediate
Platform: TradeStation
Broker/Data: RJO Brien
Favorite Futures: ES, CL
 
Posts: 25 since Mar 2010
Thanks: 3 given, 22 received

This sounds Great Mike!
Does this mean, the DLL's created for NT can be imported directly into Easy Language & we don't have to convert the indicator or strategy to Easy Language?

If not I wish there was an easy way to do this, please let me know if you have any ideas on easy portability between NT & Easy Language.

Reply With Quote
The following user says Thank You to thinkfuture for this post:
 
  #3 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,353 given, 83,234 received



thinkfuture View Post
This sounds Great Mike!
Does this mean, the DLL's created for NT can be imported directly into Easy Language & we don't have to convert the indicator or strategy to Easy Language?

If not I wish there was an easy way to do this, please let me know if you have any ideas on easy portability between NT & Easy Language.

No, it's not that simple.

It just means if there is something you want to do that can't be done in EasyLanguage, you could pass variables to/from a DLL and have your C++ do it.

As for NT -> EL conversion, it is case by case. I suggest creating a new thread here in the EasyLanguage Programming section for each indicator you want converted, attach a screen shot or two and the NinjaTrader .cs source, and then someone can probably covert it.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:
 
  #4 (permalink)
Elite Member
Cary, NC
 
Futures Experience: Advanced
Platform: MC, NT, Python, R
Broker/Data: FXCM, IB, Oanda, IQFeed
Favorite Futures: 6E, CL, EUR/USD
 
Fu510n's Avatar
 
Posts: 96 since Oct 2009
Thanks: 729 given, 81 received

MultiCharts 7.x DLL test harness/example


Big Mike View Post
This example is for Visual Studio C++

Courtesy user wegi from MultiCharts forum:
TS SUPPORT :: View topic - Request : dll example

VS: New - Project - Win32 DLL

 
Code
                            
extern "C" LPCSTR __declspecdllexport __stdcall intToAsc(int v

 
   try{ 
 
      
char buffer [255]; 
      
sprintf (buffer,"%c"v); 
 
      return 
buffer
 
   } 
   catch(...){ 
      
LPCSTR sValue "ERR EXCEPTION"
        return 
sValue
   } 
 

Then create a DEF file to declare the functions exported:

 
Code
                            
EXPORTS    intToAsc 

Then use this EasyLanguage code:

 
Code
                            


vars
tab(""); 
 
DefineDLLFunc"dlltest.dll",  lpstr"intToAsc"int
 
if 
tab "" then tab intToAsc(9); 
Mike

Sooo...

I'm in the middle of trying to convert the (futures.io (formerly BMT) Elite) "Myst" strategy from NinjaTrader to MultiCharts 7.4 which lead me down a path trying to implement some of the toolbar functionality that NT handles natively in C# as a C/C++ DLL. I may go the C# or even PowerBasic DLL route at some point, but wanted to start with the most direct method first. Given I've yet to try to extend MC via DLLs, this seemed like a worthwhile exercise to see what was involved. I read the TradeStation/EasyLanguage PDF references and several postings on the web that specifically state that function prototypes need to be defined as "__stdcall" rather than "__cdecl" but MC was unable to locate the functions I defined via DefineDLLFunc due to the mangling that occurred by declaring the functions as "__stdcall" (e.g. bad_function( int ) is exposed as _bad_function@4).

I shot MC support an Email and they referred me to GlobalVariable.dll which exposes the functions without "mangling" the function names which makes me wonder if they used the recommended "__stdcall" method as well - requests for access to the GlobalVarialble.dll source haven't been answered .

I wrote a quickee C/C++ test harness using "__cdecl" (on Visual Studio 2010) that others may find helpful. I'd still be interested in hearing if anyone has been able to create and call DLLs by defining functions using "__stdcall" - attempts at going that route lead MC to report "Can't find function "blah" in dll.". These functions do nothing beyond returning the value passed, but it's a start (K.I.S.S.).

-Guy

p.s. BTW, wouldn't your example above return a string pointer from a stack frame that may cause "bad bahavior" - just curious - it's been a while since I've dabbled in C/C++...
 
Code
                            
// MystToolBarWin32.h


#ifdef MYSTTOOLBARWIN32_EXPORTS
#define MYSTTOOLBARWIN32_API __declspec(dllexport)
#else
#define MYSTTOOLBARWIN32_API __declspec(dllimport)
#endif

extern "C" {
    
MYSTTOOLBARWIN32_API int __stdcall bad_functionint v );
    
MYSTTOOLBARWIN32_API int __cdecl good_functionint v );

    
MYSTTOOLBARWIN32_API unsigned char  __cdecl test_byteunsigned char b );
    
MYSTTOOLBARWIN32_API char           __cdecl test_charchar b );
    
MYSTTOOLBARWIN32_API LPSTR          __cdecl test_lpstrLPSTR s );

    
MYSTTOOLBARWIN32_API unsigned short __cdecl test_wordunsigned short w );
    
MYSTTOOLBARWIN32_API unsigned int   __cdecl test_dwordunsigned int dw );
    
MYSTTOOLBARWIN32_API unsigned int   __cdecl test_boolunsigned int b );
    
MYSTTOOLBARWIN32_API int            __cdecl test_intint i );
    
MYSTTOOLBARWIN32_API long           __cdecl test_longlong l );

    
MYSTTOOLBARWIN32_API float         __cdecl test_floatfloat f );
    
MYSTTOOLBARWIN32_API double        __cdecl test_doubledouble d );

 
Code
                            
// MystToolBarWin32.cpp : Defines the exported functions for the DLL application.


#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"

#include "MystToolBarWin32.h"

extern "C" MYSTTOOLBARWIN32_API int __stdcall bad_functionint v )
{
    return 
123;
}

extern "C" MYSTTOOLBARWIN32_API int __cdecl good_functionint v )
{
    return 
456;
}

extern "C" MYSTTOOLBARWIN32_API unsigned char __cdecl test_byteunsigned char b )
{
    return 
b;
}

extern "C" MYSTTOOLBARWIN32_API char __cdecl test_charchar b )
{
    return 
b;
}

extern "C" MYSTTOOLBARWIN32_API LPSTR __cdecl test_lpstrLPSTR s )
{
    return 
s;
}

extern "C" MYSTTOOLBARWIN32_API unsigned short __cdecl test_wordunsigned short w )
{
    return 
w;
}

extern "C" MYSTTOOLBARWIN32_API unsigned int __cdecl test_dwordunsigned int dw )
{
    return 
dw;
}

extern "C" MYSTTOOLBARWIN32_API unsigned int __cdecl test_boolunsigned int b )
{
    return 
b;
}

extern "C" MYSTTOOLBARWIN32_API int __cdecl test_intint i )
{
    return 
i;
}

extern "C" MYSTTOOLBARWIN32_API long __cdecl test_longlong l )
{
    return 
l;
}

extern "C" MYSTTOOLBARWIN32_API float __cdecl test_floatfloat f )
{
    return 
f;
}

extern "C" MYSTTOOLBARWIN32_API double __cdecl test_doubledouble d )
{
    return 
d;

 
Code
                            
// Fu510nDLLTest - MultiCharts DLL test harness (writes output to Output window)


vars:
    
int idx),
    
int n),
    
float f0.0 ),
    
double d10.0 ),
    
s1"string" ),
    
s2"" );

array:
    
nArray[9]( );

DefineDLLFunc"MystToolBarWin32.dll"byte,   "test_byte",   byte;   // 1 byte integer
DefineDLLFunc"MystToolBarWin32.dll"char,   "test_char",   char;   // 1 byte integer
DefineDLLFunc"MystToolBarWin32.dll"word,   "test_word",   word;   // 2 byte unsigned integer
DefineDLLFunc"MystToolBarWin32.dll"dword,  "test_dword",  dword;  // 4 byte unsigned integer
DefineDLLFunc"MystToolBarWin32.dll"bool,   "test_bool",   bool;   // 4 byte boolean
DefineDLLFunc"MystToolBarWin32.dll"int,    "test_int",    int;    // 4 byte signed integer
DefineDLLFunc"MystToolBarWin32.dll"long,   "test_long",   long;   // 4 byte signed integer
DefineDLLFunc"MystToolBarWin32.dll"float,  "test_float",  float;  // 4 byte floating point
DefineDLLFunc"MystToolBarWin32.dll"double"test_double"double// 8 byte floating point
DefineDLLFunc"MystToolBarWin32.dll"LPSTR,  "test_lpstr",  LPSTR;  // pointer to a char

once begin

    nArray
[0] = 0;
    
nArray[1] = 127;
    
nArray[2] = 128;
    
nArray[3] = 255;
    
nArray[4] = -1;
    
nArray[5] = 256;
    
nArray[6] = 65536;
    
nArray[7] = 65536*256;
    
nArray[8] = 65536*65536;

    
ClearDebug();

    for 
idx 0 to 5 begin
        n 
test_bytenArray[idx] );
        
MessageLog"test_byte( "nArray[idx]:0:0" )=[ "n:0:0" ]" );
    
end;

    
MessageLog"" );

    for 
idx 0 to 5 begin
        n 
test_charnArray[idx] );
        
MessageLog"test_char( "nArray[idx]:0:0" )=[ "n:0:0" ]" );
    
end;

    
MessageLog"" );

    
s2 test_lpstrs1 );
    
MessageLog"test_lpstr( "s1" )=[ "s2 " ]" );

    
MessageLog"" );

    for 
idx 0 to 6 begin
        n 
test_wordnArray[idx] );
        
MessageLog"test_word( "nArray[idx]:0:0" )=[ "n:0:0" ]" );
    
end;

    
MessageLog"" );

    for 
idx 0 to 8 begin
        n 
test_dwordnArray[idx] );
        
MessageLog"test_dword( "nArray[idx]:0:0" )=[ "n:0:0" ]" );
    
end;

    
MessageLog"" );

    
MessageLog"test_bool( False )=[ "test_boolFalse ), " ]" );
    
MessageLog"test_bool( True )=[ "test_boolTrue ), " ]" );

    
MessageLog"" );

    
nArray[8] = 65536*32768-1;
    
nArray[9] = -(65536*32768);

    for 
idx 0 to 9 begin
        n 
test_intnArray[idx] );
        
MessageLog"test_int( "nArray[idx]:0:0" )=[ "n:0:0" ]" );
    
end;

    
MessageLog"" );

    for 
idx 0 to 9 begin
        n 
test_longnArray[idx] );
        
MessageLog"test_long( "nArray[idx]:0:0" )=[ "n:0:0" ]" );
    
end;

    
MessageLog"" );

    
test_float123456.123456 );
    
MessageLog"test_float( "123456.123456:8:8" )=[ "f:8:8" ]" );

    
MessageLog"" );

    
d1 test_double12345678.12345678 );
    
MessageLog"test_double( "12345678.12345678:8:8" )=[ "d1:8:8" ]" );

end
 
Code
                            
test_byte)=[ ]

test_byte127 )=[ 127 ]
test_byte128 )=[ 128 ]
test_byte255 )=[ 255 ]
test_byte( -)=[ 255 ]
test_byte256 )=[ ]

test_char)=[ ]
test_char127 )=[ 127 ]
test_char128 )=[ -128 ]
test_char255 )=[ -]
test_char( -)=[ -]
test_char256 )=[ ]

test_lpstr( string )=[ string ]

test_word)=[ ]
test_word127 )=[ 127 ]
test_word128 )=[ 128 ]
test_word255 )=[ 255 ]
test_word( -)=[ 65535 ]
test_word256 )=[ 256 ]
test_word65536 )=[ ]

test_dword)=[ ]
test_dword127 )=[ 127 ]
test_dword128 )=[ 128 ]
test_dword255 )=[ 255 ]
test_dword( -)=[ 4294967295 ]
test_dword256 )=[ 256 ]
test_dword65536 )=[ 65536 ]
test_dword16777216 )=[ 16777216 ]
test_dword4294967296 )=[ ]

test_boolFalse )=[ FALSE ]
test_boolTrue )=[ TRUE ]

test_int)=[ ]
test_int127 )=[ 127 ]
test_int128 )=[ 128 ]
test_int255 )=[ 255 ]
test_int( -)=[ -]
test_int256 )=[ 256 ]
test_int65536 )=[ 65536 ]
test_int16777216 )=[ 16777216 ]
test_int2147483647 )=[ 2147483647 ]
test_int( -2147483648 )=[ -2147483648 ]

test_long)=[ ]
test_long127 )=[ 127 ]
test_long128 )=[ 128 ]
test_long255 )=[ 255 ]
test_long( -)=[ -]
test_long256 )=[ 256 ]
test_long65536 )=[ 65536 ]
test_long16777216 )=[ 16777216 ]
test_long2147483647 )=[ 2147483647 ]
test_long( -2147483648 )=[ -2147483648 ]

test_float123456.12345600 )=[ 123456.12500000 ]

test_double12345678.12345678 )=[ 12345678.12345678 

Reply With Quote
The following 2 users say Thank You to Fu510n for this post:
 
  #5 (permalink)
Trading Apprentice
russia kaliningrad
 
Futures Experience: Intermediate
Platform: sc, custom
Favorite Futures: es,zn,zb
 
ludvig's Avatar
 
Posts: 11 since Jan 2011
Thanks: 0 given, 9 received

Thank you Fu510n for posting this code, but I have a trouble to realize it. I copy your text into VC2010(express edition), compile, put the dll to TSSupport\Multicharts folder and after I open PL indicator on chart, i have this message:

<<EXCEPTION>>
Address: 0x65641407 ( 1701057543 )
Code: 0xC0000005 ( -1073741819 )
Continuable: 0x00000000 ( 0 )
Description: Instraction for adress "0x
ErrorCode: 0xC0000005 ( -1073741819 )
ExceptionType: 0x00000000 ( 0 )
Module: C:\Documents and Settings\All Users\Application Data\TS Support\MultiCharts\StudyServer\Studies\Dlls\Indicators\i_my_indicator.dll
Process: C:\Program Files\TS Support\MultiCharts\MultiCharts.exe
Thread ID: 0x000013F4 ( 5108 )
Time: 27.05.2012 - 01:36:02.768

Whot do you think may be the reason, can you help me?

Reply With Quote
 
  #6 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

Some references that I have not tested myself...

Step by step guide for developing a C++ DLL (Dynamic Link Library) that can be used with MultiCharts’ PowerLanguage: Extending MultiCharts Capabilities with C++ | Aurora Solutions

This thread on MultiCharts forum: MultiCharts: Trading Software for Automated Trading and Backtesting ? View topic - [Advanced Topic] Programming DLL

Nicolas

Reply With Quote
The following 4 users say Thank You to Nicolas11 for this post:
 
  #7 (permalink)
Elite Member
Cary, NC
 
Futures Experience: Advanced
Platform: MC, NT, Python, R
Broker/Data: FXCM, IB, Oanda, IQFeed
Favorite Futures: 6E, CL, EUR/USD
 
Fu510n's Avatar
 
Posts: 96 since Oct 2009
Thanks: 729 given, 81 received


ludvig View Post
Thank you Fu510n for posting this code, but I have a trouble to realize it. I copy your text into VC2010(express edition), compile, put the dll to TSSupport\Multicharts folder and after I open PL indicator on chart, i have this message:

<<EXCEPTION>>
Address: 0x65641407 ( 1701057543 )
Code: 0xC0000005 ( -1073741819 )
Continuable: 0x00000000 ( 0 )
Description: Instraction for adress "0x
ErrorCode: 0xC0000005 ( -1073741819 )
ExceptionType: 0x00000000 ( 0 )
Module: C:\Documents and Settings\All Users\Application Data\TS Support\MultiCharts\StudyServer\Studies\Dlls\Indicators\i_my_indicator.dll
Process: C:\Program Files\TS Support\MultiCharts\MultiCharts.exe
Thread ID: 0x000013F4 ( 5108 )
Time: 27.05.2012 - 01:36:02.768

What do you think may be the reason, can you help me?

32-bit vs. 64-bit Multicharts? (i.e. the DLL has to match whatever version of Multicharts you are running).

Just a thought,
Guy

p.s. I've since upgraded to using VS2013 Community Edition to generate 64-bit DLLs to use with MC64. The same code above "still works", in addition to a PureBasic variant which generates the exact same output. I can post new/updated sources for both versions if anyone is interested...

Reply With Quote
 
  #8 (permalink)
Elite Member
Frankfurt Germany
 
Futures Experience: Intermediate
Platform: MetaTrader, MultiCharts
Favorite Futures: Forex, ES, GC, strange synthetic creatures
 
Posts: 16 since Nov 2014
Thanks: 19 given, 14 received


Fu510n View Post
...function prototypes need to be defined as "__stdcall" rather than "__cdecl" but MC was unable to locate the functions ... due to the mangling
that occurred by declaring the functions as "__stdcall" (e.g. bad_function( int ) is exposed as _bad_function@4).
...
I wrote a quickee C/C++ test harness using "__cdecl" (on Visual Studio 2010) that others may find helpful. I'd still be interested in hearing
if anyone has been able to create and call DLLs by defining functions using "__stdcall"...

There are two ways to solve the mangling problem.

1) With DEF file: export the function names via a DEF file, there you can name them whatever you want. Specify the functions by ordinal numbers.

2) Without DEF file: Use linker comments. A lot of people will not like it but it's the simpliest way. The pragma statements belong anywhere in the function body.

Both ways work with VS2008 Pro, I can't test with later versions here but it should do.

Peter

 
Code
                            
//#define EXPORT extern "C" __declspec(dllexport)                         // standard way, we don't use it here

#define EXPORT   comment(linker, "/EXPORT:"__FUNCTION__"="__FUNCDNAME__)  // export unmangled names w/o DEF file

int WINAPI GetLastWin32Error() {  // WINAPI translates to __stdcall
   
return(GetLastError());
   
#pragma EXPORT

Resulting DLL in PE Explorer:

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Last edited by MT4Survivor; February 13th, 2015 at 11:37 AM. Reason: Update and screenshot attached
Reply With Quote
The following 2 users say Thank You to MT4Survivor for this post:
 
  #9 (permalink)
Elite Member
Cary, NC
 
Futures Experience: Advanced
Platform: MC, NT, Python, R
Broker/Data: FXCM, IB, Oanda, IQFeed
Favorite Futures: 6E, CL, EUR/USD
 
Fu510n's Avatar
 
Posts: 96 since Oct 2009
Thanks: 729 given, 81 received

PureBasic DLL


Fu510n View Post
32-bit vs. 64-bit Multicharts? (i.e. the DLL has to match whatever version of Multicharts you are running).

Just a thought,
Guy

p.s. I've since upgraded to using VS2013 Community Edition to generate 64-bit DLLs to use with MC64. The same code above "still works", in addition to a PureBasic variant which generates the exact same output. I can post new/updated sources for both versions if anyone is interested...

I received a request for the 64-bit PureBasic (5.31) source from another futures.io (formerly BMT) member, so I'll embed below...

MC64DLLTest.pb
 
Code
;
; ------------------------------------------------------------
;
;   PureBasic - DLL example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;
; This example is a skeleton to build easely a DLL using PureBasic
; The dll is created in the 'Compilers' directory, under the
; 'purebasic.dll' name. An associated '.lib' is generated to use
; with VisualC++.
;
;
; Rules to follow:
;   - Never write code outside a procedure, except for variables
;   or structure declaration.
;   
;   - DirectX Init routines must not be initialized in the the
;   AttachProcess() procedure
;   
;   - There is 4 procedures automatically called: AttachProcess(),
;   DetachProcess(), AttachThread() and DetachThread(). If you don't
;   need them, just remove them.
;

#TESTDLL = 0

CompilerIf #TESTDLL = 0

  CompilerIf #PB_Compiler_OS = #PB_OS_Windows

    ; These 4 procedures are Windows specific
    ;

    ; This procedure is called once, when the program loads the library
    ; for the first time. All init stuffs can be done here (but not DirectX init)
    ;
    ProcedureDLL AttachProcess(Instance)
    EndProcedure
  
    ; Called when the program release (free) the DLL
    ;
    ProcedureDLL DetachProcess(Instance)
    EndProcedure
  
    ; Both are called when a thread in a program call or release (free) the DLL
    ;
    ProcedureDLL AttachThread(Instance)
    EndProcedure
  
    ProcedureDLL DetachThread(Instance)
    EndProcedure

  CompilerEndIf

  ; Real code start here..
  ;
  ProcedureDLL EasyRequester(Message$)
    MessageRequester("EasyRequester !", Message$)
  EndProcedure

  ProcedureDLL.i bad_function( v.i )
    ProcedureReturn 123
  EndProcedure

  ProcedureCDLL.i good_function( v.i )
    ProcedureReturn 456
  EndProcedure

  ProcedureCDLL.b test_byte( b.b )
    ProcedureReturn b.b * 2
  EndProcedure

  ProcedureCDLL.c test_char( b.c )
    ProcedureReturn b.c
  EndProcedure

  ProcedureCDLL.s test_lpstr( s.s )
    ProcedureReturn s.s
  EndProcedure

  ProcedureCDLL.w test_word( w.w )
     ProcedureReturn w.w
  EndProcedure

  ProcedureCDLL.l test_dword( dw.l )
    ProcedureReturn dw.l
  EndProcedure

  ProcedureCDLL test_bool( b.b )
    ProcedureReturn b.b
  EndProcedure

  ProcedureCDLL.i test_int( i.i )
    ProcedureReturn i.i * 2
   EndProcedure

  ProcedureCDLL.l test_long( l.l )
    ProcedureReturn l.l * 2
  EndProcedure

  ProcedureCDLL.f test_float( f.f )
    ProcedureReturn f.f
  EndProcedure

  ProcedureCDLL.d test_double( d.d )
    ProcedureReturn d.d
  EndProcedure

CompilerElse

  If OpenLibrary(0, "MC64DLLTest.dll") Or OpenLibrary(0, "MC64DLLTest.so")
    CallFunction(0, "EasyRequester", @"Hello World!")  
  EndIf

CompilerEndIf

...and the EasyLanguage MC source that calls the above DLL...
 
Code
// Fu510nDLLTest - MultiCharts DLL test harness (writes output to Output window)

vars:
	int idx( 0 ),
	int n( 0 ),
	float f( 0.0 ),
	double d1( 0.0 ),
	s1( "string" ),
	s2( "" );

array:
	nArray[9]( 0 );

DefineDLLFunc: "MC64DLLTest.dll", byte,   "test_byte",   byte;   // 1 byte integer
DefineDLLFunc: "MC64DLLTest.dll", char,   "test_char",   char;   // 1 byte integer
DefineDLLFunc: "MC64DLLTest.dll", word,   "test_word",   word;   // 2 byte unsigned integer
DefineDLLFunc: "MC64DLLTest.dll", dword,  "test_dword",  dword;  // 4 byte unsigned integer
DefineDLLFunc: "MC64DLLTest.dll", bool,   "test_bool",   bool;   // 4 byte boolean
DefineDLLFunc: "MC64DLLTest.dll", int,    "test_int",    int;    // 4 byte signed integer
DefineDLLFunc: "MC64DLLTest.dll", long,   "test_long",   long;   // 4 byte signed integer
DefineDLLFunc: "MC64DLLTest.dll", float,  "test_float",  float;  // 4 byte floating point
DefineDLLFunc: "MC64DLLTest.dll", double, "test_double", double; // 8 byte floating point
DefineDLLFunc: "MC64DLLTest.dll", LPSTR,  "test_lpstr",  LPSTR;  // pointer to a char

once begin

	nArray[0] = 0;
	nArray[1] = 127;
	nArray[2] = 128;
	nArray[3] = 255;
	nArray[4] = -1;
	nArray[5] = 256;
	nArray[6] = 65536;
	nArray[7] = 65536*256;
	nArray[8] = 65536*65536;

	ClearDebug();

	for idx = 0 to 5 begin
		n = test_byte( nArray[idx] );
		MessageLog( "test_byte( ", nArray[idx]:0:0, " )=[ ", n:0:0, " ]" );
	end;

	MessageLog( "" );

	for idx = 0 to 5 begin
		n = test_char( nArray[idx] );
		MessageLog( "test_char( ", nArray[idx]:0:0, " )=[ ", n:0:0, " ]" );
	end;

	MessageLog( "" );

	s2 = test_lpstr( s1 );
	MessageLog( "test_lpstr( ", s1, " )=[ ", s2 , " ]" );

	MessageLog( "" );

	for idx = 0 to 6 begin
		n = test_word( nArray[idx] );
		MessageLog( "test_word( ", nArray[idx]:0:0, " )=[ ", n:0:0, " ]" );
	end;

	MessageLog( "" );

	for idx = 0 to 8 begin
		n = test_dword( nArray[idx] );
		MessageLog( "test_dword( ", nArray[idx]:0:0, " )=[ ", n:0:0, " ]" );
	end;

	MessageLog( "" );

	MessageLog( "test_bool( False )=[ ", test_bool( False ), " ]" );
	MessageLog( "test_bool( True )=[ ", test_bool( True ), " ]" );

	MessageLog( "" );

	nArray[8] = 65536*32768-1;
	nArray[9] = -(65536*32768);

	for idx = 0 to 9 begin
		n = test_int( nArray[idx] );
		MessageLog( "test_int( ", nArray[idx]:0:0, " )=[ ", n:0:0, " ]" );
	end;

	MessageLog( "" );

	for idx = 0 to 9 begin
		n = test_long( nArray[idx] );
		MessageLog( "test_long( ", nArray[idx]:0:0, " )=[ ", n:0:0, " ]" );
	end;

	MessageLog( "" );

	f = test_float( 123456.123456 );
	MessageLog( "test_float( ", 123456.123456:8:8, " )=[ ", f:8:8, " ]" );

	MessageLog( "" );

	d1 = test_double( 12345678.12345678 );
	MessageLog( "test_double( ", 12345678.12345678:8:8, " )=[ ", d1:8:8, " ]" );

end;

...which outputs...
 
Code
test_byte( 0 )=[ 0 ]
test_byte( 127 )=[ 254 ]
test_byte( 128 )=[ 0 ]
test_byte( 255 )=[ 254 ]
test_byte( -1 )=[ 254 ]
test_byte( 256 )=[ 0 ]

test_char( 0 )=[ 0 ]
test_char( 127 )=[ 127 ]
test_char( 128 )=[ -128 ]
test_char( 255 )=[ -1 ]
test_char( -1 )=[ -1 ]
test_char( 256 )=[ 0 ]

test_lpstr( string )=[ string ]

test_word( 0 )=[ 0 ]
test_word( 127 )=[ 127 ]
test_word( 128 )=[ 128 ]
test_word( 255 )=[ 255 ]
test_word( -1 )=[ 65535 ]
test_word( 256 )=[ 256 ]
test_word( 65536 )=[ 0 ]

test_dword( 0 )=[ 0 ]
test_dword( 127 )=[ 127 ]
test_dword( 128 )=[ 128 ]
test_dword( 255 )=[ 255 ]
test_dword( -1 )=[ 4294967295 ]
test_dword( 256 )=[ 256 ]
test_dword( 65536 )=[ 65536 ]
test_dword( 16777216 )=[ 16777216 ]
test_dword( 4294967296 )=[ 0 ]

test_bool( False )=[ FALSE ]
test_bool( True )=[ TRUE ]

test_int( 0 )=[ 0 ]
test_int( 127 )=[ 254 ]
test_int( 128 )=[ 256 ]
test_int( 255 )=[ 510 ]
test_int( -1 )=[ -2 ]
test_int( 256 )=[ 512 ]
test_int( 65536 )=[ 131072 ]
test_int( 16777216 )=[ 33554432 ]
test_int( 2147483647 )=[ -2 ]
test_int( -2147483648 )=[ 0 ]

test_long( 0 )=[ 0 ]
test_long( 127 )=[ 254 ]
test_long( 128 )=[ 256 ]
test_long( 255 )=[ 510 ]
test_long( -1 )=[ -2 ]
test_long( 256 )=[ 512 ]
test_long( 65536 )=[ 131072 ]
test_long( 16777216 )=[ 33554432 ]
test_long( 2147483647 )=[ -2 ]
test_long( -2147483648 )=[ 0 ]

test_float( 123456.12345600 )=[ 123456.12500000 ]

test_double( 12345678.12345678 )=[ 12345678.12345678 ]

Reply With Quote
The following user says Thank You to Fu510n for this post:
 
  #10 (permalink)
Elite Member
Sliema+Sliema/Malta
 
Futures Experience: None
Platform: Multicharts, Proprietary
Broker/Data: IB,Barcharts.com
Favorite Futures: Stocks,Futures
 
Posts: 21 since Mar 2014
Thanks: 75 given, 12 received


Thanks!

Best wishes,


Alex

Reply With Quote

Reply



futures io > > > > > Calling external DLL from EasyLanguage

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling an Optimization in a Strategy serac NinjaTrader Programming 17 September 2nd, 2015 03:25 PM
Gold - I'm calling the top cpi65 Commodities Futures Trading 65 February 19th, 2012 05:32 AM
External Data Feed market replay software PeterOhlson NinjaTrader 14 July 31st, 2011 05:12 PM
Calling GomiCD into GomiLadder kashter NinjaTrader Programming 2 May 9th, 2011 07:35 PM
External DLL from Ninjatrader ehlaban NinjaTrader Programming 11 June 13th, 2010 12:42 PM


All times are GMT -4. The time now is 08:15 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-15 in 0.21 seconds with 19 queries on phoenix via your IP 54.234.247.118