Hi,
I have at least 2, which require familiarity with C++ and, to some extent, .NET. Project 1, the simpler of the two, is to write a simple "wrapper" for a .NET assembly so it is callable as a C++ DLL. If Project 1 goes well, Project 2 would be a more elaborate project involving real-time SQL queries/updates to an Access database (but that's getting ahead of ourselves).
Background:
I am a trader and use a financial platform called TradeStation, which has an embedded programming language/environment called "EasyLanguage" (a derivative of Pascal (Delphi)). I am very fluent in EasyLanguage and write all of my trading systems (buy/sell rules) in it. It also has (limited) support enabling one to call external DLLs, using the '_stdcall' convention -- typically to do advanced math calculations, but other things as well (disk I/O, etc.). The support for external DLLs has some important limitations; attached is a brief summary of what conventions must be followed when writing a TradeStation-compatible DLL. Two limitations: 1) the interface does not support variants; 2) TradeStation can accept pointers -- but for numerics only (not strings).
Project Description:
If you go to [login to view URL] you will find a (free) .NET assembly which reads and writes Excel (.xls) files. I need to be able to call this as a DLL, for both file reading and writing. However, to make it TradeStation-compatible, I need a C++ wrapper written for it. Below, I attach some info from TradeStation, outlining what needs to be done to create such a wrapper (also included is some possibly useful information about VB.NET...).
Please let me know if you are interested (or if you have further questions).
Thanks,
Ian MacAuslan
=========================
How it Works
The process by which code written in VB.NET is made "accessible" to TradeStation is fairly straightforward. The VB.NET function code is created as a "COM Interop" class. This allows the types in the .NET assembly to be exposed to COM. When compiled, the VB.NET code generates and automatically registers on the development computer a type library (.tlb file), as well as a DLL file. Separately, a C++ "wrapper" DLL must be created that imports this type library. TradeStation then calls this C++ wrapper DLL. The wrapper DLL calls the .NET-created DLL, based on the information provided by the imported type library.
This architecture allows primary computational coding to be done in the .NET language, which is able to use all of the functions provided by the EasyLanguage Extension SDK ([login to view URL]). For example, the .NET language (VB.NET in this demonstration) is able to access EasyLanguage price and variable values, etc.
A relatively small amount of C++ coding is required, however, in order to create the "wrapper" DLL functions that TradeStation calls. In the example provided, additional C++ code has been provided to handle errors and to perform conversions between string types.
--------------------------------------------------------------------------------
How to Create a TradeStation-compatible VB.NET Class
To create a TradeStation-compatible VB.NET class (function), the following steps may be followed. A demonstration class is provided in the zip file Interop Demo - VB [login to view URL], posted above.
1.) Start Visual Studio. The following instructions presume that Visual Studio 2005 is used. However, it may be possible to follow these instructions, with minor variations, in other .NET versions of Visual Studio.
2.) Create a new Visual Basic Class Library (File -> New -> Project -> Visual Basic -> Windows -> Select "Class Library" from the Visual Studio installed templates).
3.) Delete the automatically created class in the project (usually named [login to view URL]).
4.) Add a COM class to the project (right-click on the ClassLibrary name in the Solution Explorer window (by default, ClassLibrary1) -> Add -> New Item -> COM Class).
5.) Add a reference to the TS Kit type library if it is desired to use the EasyLanguage Extension SDK in your project (Project -> Add Reference -> COM tab -> tskit 1.0 Type Library). Note: Other TradeStation type libraries are also listed. However, the TS Kit is contained in the one with this exact name: "tskit 1.0 Type Library".
5.) Add such Public Functions to the class as may be desired.
6.) Compile the class (dll).
7.) You may wish to place the compiled DLL into your installation's equivalent to this subdirectory, so that both TradeStation and Windows can easily find it:
C:WINDOWSsystem32
8.) If the DLL is to be used on the development computer, no additional steps are required to register the type library. However, if the DLL is to be transferred to another machine, then steps like those outlined above, under "Running the Demo", steps (5) and (6), will be required in order to create and register the type library.
--------------------------------------------------------------------------------
How to Create a TradeStation-compatible C++ Wrapper DLL
The process of creating a "wrapper" TradeStation-compatible C++ DLL in Visual Studio 2005 is very similar to the process used to create a normal TradeStation-compatible C++ DLL.
1.) Start Visual Studio. The following instructions presume that Visual Studio 2005 is used. However, it may be possible to follow these instructions, with minor variations, in other .NET versions of Visual Studio.
2.) Create a new Visual C++ Win32 DLL project (File -> New -> Project -> Visual C++ -> Win32 -> Select "Win32 Project" from the Visual Studio installed templates). When the Win32 Application Wizard dialog box appears, click "Next >". On the second dialog box of the Wizard, choose DLL as the "Application type", and "Empty Project" as the "Additional options". Click "Finish" to complete the Wizard.
3.) Create a C++ code file. See the files contained in the zip file Interop Demo - CPP [login to view URL], above, for demonstration C++ code. The code will have to contain an import directive in order to use the types created in the .NET assembly. In this demonstration, the import directive looks like this:
#import "c:WINDOWSsystem32InteropDemo_VBCode.tlb" raw_interfaces_only no_namespace
4.) After the type library for the .NET assembly has been created, it will be possible to compile the C++ DLL that imports this type library.
5.) You may wish to place the compiled DLL into your installation's equivalent to this subdirectory, so that both TradeStation and Windows can easily find it:
C:WINDOWSsystem32
Please post as questions arise...
Kindest regards,
John Bruch, EasyLanguage Engineer
TradeStation Securities, Inc.
Have you seen the New EasyLanguage FAQ?
You can also Search the Support Archives!