[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: trying again to write dll for ts6



PureBytes Links

Trading Reference Links

At 10:07 AM 05/23/2002, Mike Eggleston wrote:
>I'm attempting to write an external to interface with other software. I
>have created a test case for the communication between TS6 and the dll.  I
>have been unable so far to get this dll interface to work. Would you please
>look at the code and tell me what is missing.
>
>Mike


I'm a little rusty on this since I haven't done it for a while, but I recall having two problems that needed addressing. Unfortunately neither of these would have resulted in the peculiar message you received. I hope my comments are still relevant and I'm not sending you on a wild goose chase.

One problem is that the functions must be marked for export. Perhaps that's taken care of by the (dllexport) line. I recall having a .res file that explicitly listed the functions for export.

Secondly, if you are using C++, you have to know that function names are normally "mangled". This is something the compiler does. It combines the function name you give it and the argument types to create a unique internal function name that you never see. This is how the language supports polymorphism, so that the same function can apparently be called with different argument lists. In any case, you don't want mangling turned on, otherwise your function will never be found by the name you think it has. There should be a switch to prevent name mangling, or you can compile your DLL as "C" rather than "C++".

You might be interested to know that the DLL calling requirements of TS are not special in any way. Once you have built your DLL, you can call it from Excel or other apps as well. In fact, if you really don't trust TS, you can build your DLL and test with Excel first. Once you have it working there, then you know the only problem is calling it properly from TS.

Perhaps somewhere you could find a small sample of code that already works with TS. Sorry, I don't have one to provide.

HTH,

Mike G.

>-------------- C code -----------------
>
>#include <windows.h>
>#include <time.h>
>#include <stdio.h>
>#include <sys/types.h>
>
>#ifdef __cplusplus
>extern "C" {
>#endif
>        void __declspec(dllexport) CCHISTADDCHAIN(int group, int id, int timeinterval);
>#ifdef __cplusplus
>}
>#endif
>
>void __declspec(dllexport) CCHISTADDCHAIN(int group, int id, int timeinterval)
>{
>        FILE *fp = fopen("c:\\temp\\cctest1", "a");
>        time_t tm;
>        (void) time(&tm);
>        (void) fprintf(fp, "%s received g=%d i=%d t=%d\n", group, id, timeinterval);
>        (void) fclose(fp);
>}
>----------------------------------------
>
>-------------- EL Indicator ------------
>Inputs: price(c), group(1), indid(1);
>
>DefineDLLFunc: "c:\tmp\charthistory.dll", VOID, "CCHISTADDCHAIN", int, int, int;
>
>if currentbar = 1 then begin
>        CCHistAddChain(group, indid, BarInterval);
>end;
>plot1(price);
>----------------------------------------
>
>The error I receive from TS6 when this indicator is turned on is:
>The instruction at "0x03764e3c" referenced memory at "0x00000001". The
>memory could not be "read".