logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
jhughey  
#1 Posted : Tuesday, May 26, 2009 2:16:55 PM(UTC)
jhughey

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/19/2008(UTC)
Posts: 19
Location: New York State

Was thanked: 2 time(s) in 1 post(s)
Hello,

Being new to the use of MDK, I would like to better understand *how* the MDK uses code to create a DLL that will be used by the Metastock application. I have seen the examples in the MDK User's Manual, which I am sure will be very helpful as I progress. I have also looked/searched in vain for simple MDK examples in this forum.

At this point, to free myself from a mental block, it would be very beneficial to me if I did not have to start off with a multi-paged, moving-average MDK C++ painting of a Rembrandt. I simply want to learn how to put a dab of paint on the canvas.

For example, it would be very helpful to see an example that takes the charted security's data and returns the CLOSE to the MS chart.

Could someone *please* post a *complete* C/C++ example of MDK code that can be use to create such a DLL file.


Thanks for your help!
wabbit  
#2 Posted : Tuesday, May 26, 2009 10:31:20 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,106
Location: Perth, Western Australia

Was thanked: 12 time(s) in 12 post(s)
Joe,

Have a look in the MDK directory for the MSX samples: C:\Program Files\Equis\MDK\MSX\C\CSampleDLL.dll

It contains three simple functions and is an adequate place to start.


Hope this helps.

wabbit [:D]

jhughey  
#3 Posted : Wednesday, May 27, 2009 10:25:48 PM(UTC)
jhughey

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/19/2008(UTC)
Posts: 19
Location: New York State

Was thanked: 2 time(s) in 1 post(s)
Thanks Wabbit!

CSampleDLL.cpp seems to compile ok, but I have a (non-MDK) Microsoft linker glitch, which should be eventually resolvable, once I can figure out who has the correct answer in the Microsoft Forums. http://social.msdn.micro...9-4707-a22e-8cdf596926a6

Hopefully it also does not involve C++ name-mangling, but tmainCRTStartup has three "_" characters in front of it, while CSampleDLL.cpp has name-mangling disabled.

MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

Will keep you posted. Kudos.


wabbit  
#4 Posted : Wednesday, May 27, 2009 10:41:44 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,106
Location: Perth, Western Australia

Was thanked: 12 time(s) in 12 post(s)
Have you included the .def file in the project?


wabbit [:D]

wabbit  
#5 Posted : Friday, May 29, 2009 9:06:32 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,106
Location: Perth, Western Australia

Was thanked: 12 time(s) in 12 post(s)
I was doing some "stuff" and wondered how "simple" a dll could get. I came up with this to return the CLOSE price, which I think is about as simple as things could get:

Code:
#include <windows.h>
#include "MSXStruc.h"

#define DLL_EXPORT extern "C" __declspec(dllexport)


DLL_EXPORT BOOL __stdcall MSXInfo (MSXDLLDef *a_psDLLDef)
{
 strncpy (a_psDLLDef->szCopyright, "http:\\\\www.wabbit.com.au", sizeof(a_psDLLDef->szCopyright)-1);
 a_psDLLDef->iNFuncs = 1;
 a_psDLLDef->iVersion = MSX_VERSION;
 return MSX_SUCCESS;
}

DLL_EXPORT BOOL __stdcall MSXNthFunction (int a_iNthFunc, MSXFuncDef *a_psFuncDef)
{
 strncpy (a_psFuncDef->szFunctionName, "rClose", sizeof(a_psFuncDef->szFunctionName)-1);
 strncpy (a_psFuncDef->szFunctionDescription, "Returns the CLOSE price.", sizeof(a_psFuncDef->szFunctionDescription)-1);
 a_psFuncDef->iNArguments = 0;
 return MSX_SUCCESS;
}

DLL_EXPORT BOOL __stdcall rClose (const MSXDataRec *a_psDataRec, const MSXDataInfoRecArgsArray *a_psDataInfoArgs, const MSXNumericArgsArray *a_psNumericArgs, const MSXStringArgsArray *a_psStringArgs, const MSXCustomArgsArray *a_psCustomArgs, MSXResultRec *a_psResultRec)
{
 
 for (int i=a_psDataRec->sClose.iFirstValid; i<=a_psDataRec->sClose.iLastValid; i++)
 a_psResultRec->psResultArray->pfValue[ i ] = a_psDataRec->sClose.pfValue[ i ];
 
 a_psResultRec->psResultArray->iFirstValid = a_psDataRec->sClose.iFirstValid;
 a_psResultRec->psResultArray->iLastValid = a_psDataRec->sClose.iLastValid;
 return MSX_SUCCESS;
}


Compiles without a .def under VC++2008, but not under VC6 ?? (I must have a compiler switch set wrong?)

This example is of VERY limited use and is NOT a good example to use as a basis for learning to create MSX libraries or as a template for your own libraries.



Hope this helps.

wabbit [:D]


jhughey  
#6 Posted : Saturday, May 30, 2009 10:14:52 AM(UTC)
jhughey

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/19/2008(UTC)
Posts: 19
Location: New York State

Was thanked: 2 time(s) in 1 post(s)
This is great! Thank you Wabbit!

I think this is an excellent illustration, because it shows how one programs a minimal MDK DLL interface to Metastock. It is very useful for educating new users of MDK, because the calculation details do not distract from the understanding the essential programming mechanism. It is the best way to teach, and the best way to learn.

Last night I was able to get the LNK2019 error resolved. It was caused by the way the C++ project was developed. Once I started all over again and built it correctly, the problem went away. There is an excellent reference for this as well:
http://bobobobo.wordpres...aincrtstartupmsvcrtdlib/">http://bobobobo.wordpress.com/2008/01/29/error-lnk2019-error1error-lnk2019-unresolved-external-symbol-_main-referenced-in-function-___tmaincrtstartupmsvcrtdlib/

No, I haven't finished the .NET file. It is next.

Thanks again!
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.