[XM C++] DllMdlApp not causing DLL to load

Hi,

I'm trying to get MicroStation XM to load a DLL that will contain a lot of existing company logic.

I am following http://www.la-solutions.co.uk/content/MDL/MdlDll.htm as closely as I can.   I'm using MicroStation XM and VC++ 2003.

I made a simple .ma, and confirmed it worked, with a few test Key-Ins.    Then I made a DLL.  I modified my .r source to contain this DllMdlApp definition:

#define DLLAPP_CSW 1

DllMdlApp DLLAPP_CSW =

{

// MDL Application name VC++ DLL in MDLAPPS or %PATH%
"CSW", "CSMS.DLL"
};

I removed the main and command functions from my .mc file.  As a later test, I modified my makefile to not even build the .mc file.

When typing the keyin mdl load csw, MicroStation XM will load my CSW.ma but does not load the .dll.  It does not even try to load the .dll.

I have this funciton in my dll .cpp file:

extern "C" DLLEXPORT int MdlMain(int argc, char* argv[])


I do some stuff in there like AfxMessageBox() and mdlOutput_printf() and none of that happens.  Also, I am using process monitor and can see that MicroStation never even tried to open the dll upon loading of my .ma file.

That URL above said that not having a main function and having the DllMdlApp resource in the .ma should make it load the DLL.  What am I missing?  Do I need to do more to my makefile to indicate that the .ma will load a DLL.  I wonder if it's getting an automatic main() function or something like that that would cause it to not load the DLL.

Thanks

  

  • Bellamy,

    I think you are confusing loading a dll with converting my old mdl application to native code.  First you don't need to convert the code to native code to access a native code dll.  I suggest looking at the DLINK example that we deliver for how to have native functions that are called from MDL code.  The other way to go (which is more of what all the work you show here leads to) is to make the application fully native code.  One of the main part of this is to rename the old .mc file to a .cpp file and build it as a native code application from the ground up.  That means that main becomes MdlMain and the free and malloc go to dlmSystem_mdlFree and dlmSystem_mdlMalloc.  You need to set the strings in the DllMdlApp resource to be the app name and dll name without the extensions. (no .DLL).  

    I suggest that you take a step back and review the examples that are now delivered with the MicroStationSDK (yes get the 8.11 version for review only).

    HTH,

  • Hi Mark,

    Thank you for that info.

    I know for sure I want to make a fully native application and not an application similar to the DLINK example.  

    Can you tell me if MicroStation XM can support that?  What is the oldest version that can support fully native?

    Removing my .dll extension did not fix it, by itself.

    I need to build the dll in visual studio if it's possible as there are a lot of external source files with a complex configuration and the projects are already set up minus the MicroStation integration part.

    Thanks!

  • Unknown said:

    #define DLLAPP_CSW 1

    DllMdlApp DLLAPP_CSW =

    {

    // MDL Application name VC++ DLL in MDLAPPS or %PATH%
    "CSW", "CSMS.DLL"
    };

    Look at the basic example delivered with the SDK.  You'll find this in basiccmd.r...

    #define  DLLAPP_BASIC        1

    DllMdlApp DLLAPP_BASIC =
        {
        "BASIC", "basic"          // taskid, dllName
        }
    When MicroStation finds that resource type in your .ma file, it knows that it should look for the named native-code DLL.   Note the resource does not include the file extension.  The entry point MicroStation looks for is MdlMain, which has the same function signature as main().

     
    Regards, Jon Summers
    LA Solutions

  • Hi Jon,

    Thanks.  I think the issue may be that XM may be too old to support fully native applications and thus ignores the DllMDlApp.  I'm not sure, it just appears like that to me since I'm following that and it's not loading my DLL.  My XM sdk still had basic as a fully MDL application.  I dl'd the SS3 SDK and can see that in there.  I will try this on V8i SS3.  I was just trying to support older MicroStation versions.  Perhaps the complete lack of examples with fully native in the XM SDK should have been enough of a hint.

    Thanks

  • Nevermind all my rubbsih about XM maybe not supporting fully native.  This old article clearly says otherwise:

    communities.bentley.com/.../8797.aspx

    I just need to debug my issue.

  • Unknown said:
     Perhaps the complete lack of examples with fully native in the XM SDK should have been enough of a hint

    I forgot that the SDK for XM delivered conventional MDL examples.  Get hold of the SDK for V8i, which provides native-code examples.  You should be able to build those for XM.

    Unknown said:
    What is the oldest version that can support fully native?

    MicroStation V8 has supported native code from v8.0.  The SDK has become more oriented towards C++ in this century.  I think XM provided the first public version of the C++ MicroStationAPI in addition to the MDL.  Bentley Systems have discouraged us from using plain old MDL for several years — and the next version of MicroStation won't let you write MDL.

     
    Regards, Jon Summers
    LA Solutions

  • When I compile using VS2005, one thing I tend to forget is to put "MdlMain" in the .def file to make sure that function gets exported.

  • Unknown said:

    When I compile using VS2005, one thing I tend to forget is to put "MdlMain" in the .def file to make sure that function gets exported.

    Bruce:  My understanding is if you use __declspec( dllexport ) in a function definition, that you don't need to add that function to the .def.  I tried it anyway, and it didn't fix my issue.
    After building the basic example in from the SS3 SDK, I replaced the basic.dll with my DLL, and I got the messagebox from the MdlMain function when loading basic.ma, so I think my DLL is fine, and the issue is with the .ma / makefile somehow.

  • Bellamy,

    Can you send me your .mc file and the make file I will take a look at what you have.

    Rgds,

  • Mark: I just copied the basic example from the SS3 SDK which works fine, and changed it to load my dll instead of basic.dll, and am working on trimming out the stuff.  It is working fine this way.  I must have had something bad in the make file.  Having a working fully native example from the SS3 SDK is a big help.  Originally I copied mline from the XM sdk and I guess something in my changes prevented it from loading the dll.  I didn't have anything of significance, just wanted to confirm I could load a DLL I was bulding via Visual Studio at this initial step.

    Thanks for the help and suggestions all.

    Answer Verified By: bellamy