Example of Building a DLL in C++

You can build a DLL in C++ exactly as you build a DLL in C in terms of source code. Therefore, our C examples in the “SDK for Building Custom DLLs” are C++ examples as well. Refer to that for more DLL details. However, click here to download zipped files specifically compiled in Microsoft C++ (Visual Studio 6.0). We’ve compiled the DLL for you, and even included the .tpl file you’d create in the Trader Professional.

The example you will download is a trivial indicator which returns the average (also the median in this case) of the high and the low. We have not actually used any classes since our intent is only to show you how a DLL is constructed, not to demonstrate any C++ programming techniques. Here is the source code:

#define DLLF _declspec(dllexport)

DLLF void MedianPrice(float *high, float *low, float *outp, long numbars)
{
 for (long i=0; i<numbars; i++)
  outp=(high+low)/2;
}

Note – If you are fairly new to programming and don’t already know C or C++, we recommend that you use PowerBasic for your DLL programming unless you have some other reason to learn C or C++. BASIC is a much easier language than C, and C is much easier than C++. If you studied PASCAL in school, then use Delphi.

Was this article helpful?

Related Articles