1. 首页
  2. 易语言 - EasyLanguage
  3. TradeStation兼容DLL之(三) Understanding TradeStation-compatible DLL’s – Part III

TradeStation兼容DLL之(三) Understanding TradeStation-compatible DLL’s – Part III

 This is the third part of a three part blog entry in which we review the answers to some of the most common questions that arise when developing or using TradeStation-compatible DLL’s.

     1)   What programming language and development environment should I use?

     Most of the demonstration code posted in the forums was developed in Visual C++ (Visual Studio 6 or Visual Studio 2005).  Visual C++ tends to work especially well with the COM interfaces provided by the EasyLanguage Extension SDK.

     PowerBASIC, Delphi (Pascal), and other languages can be used, but the examples posted in the forum that use these languages are generally older and simpler than the C++ examples. 

The attached demonstration illustrates how code written in Visual Basic .NET or Visual Basic 2005 can be called from TradeStation EasyLanguage. More generally, it illustrates how types in a .NET assembly can be exposed to TradeStation through the DLL interface that EasyLanguage provides.

Three zip files are attached. The first, Interop Demo – General Files.zip, contains the EasyLanguage code and compiled DLL files needed to run the demonstration workspace.

The second zip file, Interop Demo – CPP Files.zip, contains the C++ demonstration project.

The third zip file, Interop Demo – VB Files.zip, contains the VB.NET demonstration project.

Running the Demo

Running the demonstration is a seven step process:

1.) Download the file Interop Demo – General Files.zip, posted above, to your computer.

2.) Extract the files contained in the zip file. Place the three DLL files into your installation’s equivalent to the following subdirectory:

    C:\WINDOWS\system32\

3.) Double-click the .ELD file, and import the indicator contained therein.

4.) Move the TradeStation workspace file, COM Interop Demo.tsw into your \Program Files\TradeStation\MyWork\ subdirectory.

5.) Ensure that you have the Microsoft .NET framework, version 2.0, installed on your computer. To do this, follow these steps:

      a.) Look for a subdirectory with a name like the following (the numbers 50727 may be different on your computer):

          C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

      b.) If you do not find a subdirectory like this on your computer, open an Internet Explorer window. From the Internet Explorer Tools menu, choose “Windows Update”. Run Windows update. You will be prompted, as one of the available updates, to install the .NET framework, version 2.0.

After you’ve completed installation of the framework, return to these instructions and continue with Step (6).

6.) Register the type library for the managed assembly (this is the type library created, in this demonstration, by the VB.NET code).

    a.) Click on the Start button on your Windows desktop… Choose “Run” from the pop-up menu that appears.

    b.) At the command prompt, type “cmd”, without the quotation marks. This will cause a DOS window to appear.

    c.) In the DOS window, at the prompt, type “CD\”, without the quotation marks. This will cause the prompt to change to “C:\>”.

    d.) Type the following, adjusting the statement so that your installation’s .NET framework subdirectory is used. Note: The version of the .NET framework used must be 2.0 or later.

The below statement, which must be typed at the “C:\>” prompt, appears to contain a space between “Rega” and “sm”. However, there should be no space there. The web site software inserts a space there because of how it handles strings longer than 50 characters. When you’re typing the line below at the C:\> prompt, type Regasm without any space.
     
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Regasm InteropDemo_VBCode.dll /tlb: InteropDemo_VBCode.tlb

7.) Open the demonstration workspace and ensure that the DLL-calculated moving average plots on the chart.

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 (tskit.dll). 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 Files.zip, 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 Class1.vb).

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:\WINDOWS\system32\

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 Files.zip, 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:\WINDOWS\system32\InteropDemo_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:\WINDOWS\system32\

2)   Where should the compiled DLL be located on my computer?

     Compiled DLL’s should generally be placed in your computer’s equivalent to this subdirectory:

          C:\Windows\System32\

     However, they can also be placed in this subdirectory:

          C:\Program Files\TradeStation N.M (Build WXYZ)\Program\

     Both of these subdirectories will automatically be searched for a DLL that is declared in EasyLanguage if the declaration does not contain a specific subdirectory.

 3)   I’ve heard that DLL function names should be capitalized?   Is that correct?  If so, why?

     In general, EasyLanguage is not case sensitive.  DLL function names are a special case — they are case sensitive.  You need not remember the exact capitalization that you used in your DLL, however, if you take advantage of a special feature of EasyLanguage that causes an automatic search for a function using all capital letters in the function name if the function is not found using the capitalization provided in the EasyLanguage function declaration.  So, if you use all capital letters in your DLL function names, you won’t have to remember the capitalization when you declare the function in EasyLanguage.  The following EasyLanguage function declaration works, despite the incorrect capitalization used:

     EasyLanguage declaration:  external:  “MyDLL.dll”, int, “MyFunc”, int ;

     DLL function prototype:  int __stdcall MYFUNC( int nMyArg ) ;

更新于 2020年6月1日

这篇文章对您有帮助吗?

相关的话题

留言评论