in Search

Request for simple example of MDK code that returns the CLOSE to MS Chart.

Last post 05-30-2009, 10:14 by jhughey. 5 replies.
Sort Posts: Previous Next
  •  05-26-2009, 14:16 29788

    Request for simple example of MDK code that returns the CLOSE to MS Chart.

    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!  

    Joe
  •  05-26-2009, 22:31 29792 in reply to 29788

    Re: Request for simple example of MDK code that returns the CLOSE to MS Chart.

    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 Big Smile [:D]


    "The question of whether a computer can think is no more interesting than the question of whether a submarine can swim."
    Edsgar W. Dijkstra

     

    MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC & MDK
    For custom MetaStock programming : http://www.wabbit.com.au
    My SkyPE status :
    My SkyPE account : wabbit.com.au

  •  05-27-2009, 22:25 29803 in reply to 29792

    Re: Request for simple example of MDK code that returns the CLOSE to MS Chart.

    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.microsoft.com/Forums/en-US/vclanguage/thread/14e85604-6929-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.



    Joe
  •  05-27-2009, 22:41 29804 in reply to 29803

    Re: Request for simple example of MDK code that returns the CLOSE to MS Chart.

    Have you included the .def file in the project?


    wabbit Big Smile [:D]


    "The question of whether a computer can think is no more interesting than the question of whether a submarine can swim."
    Edsgar W. Dijkstra

     

    MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC & MDK
    For custom MetaStock programming : http://www.wabbit.com.au
    My SkyPE status :
    My SkyPE account : wabbit.com.au

  •  05-29-2009, 21:06 29826 in reply to 29804

    Re: Request for simple example of MDK code that returns the CLOSE to MS Chart.

    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 Big Smile [:D]



    "The question of whether a computer can think is no more interesting than the question of whether a submarine can swim."
    Edsgar W. Dijkstra

     

    MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC & MDK
    For custom MetaStock programming : http://www.wabbit.com.au
    My SkyPE status :
    My SkyPE account : wabbit.com.au

  •  05-30-2009, 10:14 29832 in reply to 29826

    Re: Simpler example of code to illustrate essential MDK programming interface.

    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.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!

    Joe
View as RSS news feed in XML