Anyone have an example of C/C++ DLL that's callable from MC?

Questions about MultiCharts and user contributed studies.
marketz
Posts: 19
Joined: 09 Mar 2009

Anyone have an example of C/C++ DLL that's callable from MC?

Postby marketz » 14 Mar 2009

I have tried to create the most simple c/c++ dll and MC can't find the function in the DLL. It finds the DLL though. But not the entry point for the function. I can call functions in USER32.DLL, so I know it can be done. I am even using the same calling convention for the function, WINAPI, which translates to __stdcall. I am at a total loss on this and wasting precious time. I am about to give up on MC and cancel my subscription (technically MCFX Pro).

ts2mc
Posts: 122
Joined: 12 Jan 2009
Been thanked: 1 time

Postby ts2mc » 14 Mar 2009

hi,
find attached a simple mfcdll project for vs2008 along with an
MC signal called sigdlldemo.
be sure to copy mfcdll.dll into system32 (so that it can be found).

the script loads dll and calls the exported function add.
the result is printed to the mc console (power language editor)

tested with MC 5.0 beta 2
Attachments
tmp.rar
(89.43 KiB) Downloaded 173 times

ts2mc
Posts: 122
Joined: 12 Jan 2009
Been thanked: 1 time

Postby ts2mc » 14 Mar 2009

before checking the sample dll, simply look into the script how the DLL
is declard. this probably solves your problem.
it is simply the same as in TS.

marketz
Posts: 19
Joined: 09 Mar 2009

Postby marketz » 14 Mar 2009

before checking the sample dll, simply look into the script how the DLL
is declard. this probably solves your problem.
it is simply the same as in TS.
Well I finally got the call to work, but it crashes. I looked at your example but its MFC and I'm using VC++ Express, which doesn't come with MFC.

Here's how I define my function in my .h file:

Code: Select all

extern "C"

bool __declspec( dllexport ) myfunc(int p);
And the implementation in the .cpp file:

Code: Select all

bool __declspec( dllexport ) myfunc(int p)
{
return false;
}
I see your example uses __stdcall.

If I switch to __stdcall, MultiCharts can't find the entry point for the function. If I use it as I do above, it finds the entry point but crashes upon returning (unwinding the stack).

Clearly it expects a __stdcall, but can't find it if I use that calling convention?

Here is how I declare the function in the script:

Code: Select all

DefineDLLFunc: "mydll.DLL", bool, "myfunc", long;

marketz
Posts: 19
Joined: 09 Mar 2009

Postby marketz » 14 Mar 2009

Here's the crash report:

Code: Select all

<<EXCEPTION>>
Address: 0x6580136C ( 1702892396 )
Code: 0xC0000005 ( -1073741819 )
Continuable: 0x00000000 ( 0 )
Count: 0x00000003 ( 3 )
Description: The instruction at "0x
ErrorCode: 0xC0000005 ( -1073741819 )
ExceptionType: 0x00000000 ( 0 )
Module: C:\Documents and Settings\All Users\Application Data\TS Support\MCFX Pro\StudyServer\Studies\Dlls\Indicators\i_mydll.dll
Process: C:\Program Files\TS Support\MCFX Pro\mcfx.exe
Thread ID: 0x00000E5C ( 3676 )
Time: 14.03.2009 - 22:08:48.654

marketz
Posts: 19
Joined: 09 Mar 2009

Postby marketz » 14 Mar 2009

I finaly got this working. It required a lot of effort in the VC++ project settings, including creating a .def file for exporting the symbols. If anyone wants me to send a sample project that is non-MFC based, let me know.

Thanks to all who lent and hand for support :)

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 14 Mar 2009

For the less sophisticated programmers out there, "Powerbasic" is a great alternative for creating fast and easy DLL's with MC.

ts2mc
Posts: 122
Joined: 12 Jan 2009
Been thanked: 1 time

Postby ts2mc » 16 Mar 2009

hello,
you need to do more accurate research by your own.
i just googled 1 minute and found a simple dll sample.

attached a simple win32 DLL without MFC (so should be possible
to be built with express eidition)
Attachments
mcdll.rar
(8.15 KiB) Downloaded 127 times
mcdll.rar
simple win32 dll
(8.15 KiB) Downloaded 144 times

marketz
Posts: 19
Joined: 09 Mar 2009

Postby marketz » 17 Mar 2009

hello,
you need to do more accurate research by your own.
i just googled 1 minute and found a simple dll sample.

attached a simple win32 DLL without MFC (so should be possible
to be built with express eidition)
I did a *ton* of research, googled for hours and hours and I didn't find any examples. I'm not sure what you googled for, but no need to question the efforts here. Let's face it the documentation on this subject is not very clear and I shouldn't even have to be writing a DLL to read in a simple file in the first place, it's a little bit 1960's to be doing that with any software platform/API.

And frankly even finding a project sample on its own doesn't answer the question of what makes it work vs. a project you created yourself in VC++ Express.

It turns out that I had some of the compilation options wrong, because they were wrong by default. One of them was that you needed a .Def file, which I had, but which I hadn't specified in the project settings.


Return to “MultiCharts”