Building a simple MDL Application


This topic will guide you step by step to build the simplest Hello World native code MDL application to load and run within MicroStation CONNECT Edition (MSCE).

1. Create a folder for the project source code, e.g. D:\MDLSource\HelloWorld (or a preferred location).
2. Start a Text Editor (or IDE) and either type, or copy and paste the following text and save it as file: e.g. D:\MDLSource\HelloWorld\HelloWorld.cpp. This file contains the function MdlMain (an entry point) that will be executed upon loading of an application. In this example we simply call an MDL C API function mdlDialog_dmsgsPrint that will open and display a text message "Hello World" in a dialog message box.


/*----+ | HelloWorld.cpp | +----*/ 
#include <Mstn\MdlApi\MdlApi.h> 
extern "C" DLLEXPORT void MdlMain (int argc, WCharCP argv[]) { 
    mdlDialog_dmsgsPrint (L"Hello World");
}

Some explanations of the code above are as follow:

3.Type the following in a text editor and save it as the file D:\MDLSource\HelloWorld\HelloWorld.r. The DllMdlApp resource is defined in this file. The function of this resource is to associate the MA (actually not the MA file name but the task identifier) ​​with the specified DLL file.

#include <Mstn\MdlApi\rscdefs.r.h>
#define  DLLAPPID     1

DllMdlApp   DLLAPPID =
{
    L"HELLOWORLD", L"HelloWorld"    // taskid, dllName
}

Some explanations of the code above are as follow:

4. Copy and paste the following content into a file called HelloWorld.mke and save it under D:\MDLSource\HelloWorld. This file is the control file for generating the project. During the project generation process, bmake reads the content of the file and then calls the corresponding compiler and linker to generate the final MA and DLL from the source file.

#--------------------------------------------------------
#    MstnCE  HelloWorld.mke
#--------------------------------------------------------
PolicyFile = MicroStationPolicy.mki
DEFAULT_TARGET_PROCESSOR_ARCHITECTURE=x64

appName=HelloWorld
appObjs = $(o)$(appName)$(oext)
appRscs = $(o)$(appName).rsc
baseDir = $(_MakeFilePath)
mdlLibs = $(MSMDE)library/

%include mdl.mki

#--------------------------------------------------------
# Create needed output directories if they don't exist
#--------------------------------------------------------

always:
	 ~mkdir $(o)
	 ~mkdir $(rscObjects)
	 ~mkdir $(reqdObjs)

#--------------------------------------------------------
# Define macros for files included in our link and resource merge
#--------------------------------------------------------
DLM_NO_SIGN       = 1
DLM_OBJECT_DEST   = $(o)
DLM_NAME    =$(appName)
DLM_NO_DLS   = 1
DLM_NO_DEF   = 1
DLM_NOENTRY   = 1
DLM_OBJECT_FILES        = $(appObjs)
DLM_NO_MANIFEST   = 1
DLM_DEST   = $(mdlapps)

LINKER_LIBRARIES        = $(mdlLibs)bentley.lib \
                          $(mdlLibs)BentleyAllocator.lib \
                          $(mdlLibs)mdlbltin.lib \
                          $(mdlLibs)RmgrTools.lib \
                          $(mdlLibs)BentleyGeom.lib \
                          $(mdlLibs)DgnPlatform.lib \
                          $(mdlLibs)dgnview.lib

#-----------------------------------------------------------------------
#   Generate resource files
#-----------------------------------------------------------------------
$(o)$(appName).rsc: $(baseDir)$(appName).r

#---------------------------------------------
#	Merge the app resources using rlib
#---------------------------------------------
$(o)$(appName).mi    : $(appRscs)
	$(msg)
	> $(o)make.opt
	-o$@
	$(appRscs)
	<
	$(RLibCmd) @$(o)make.opt
	~time

appRscs =   \
    $(o)$(appName).mi \
    $(o)$(appName).rsc

$(DLM_DEST)$(appName).ma         : $(appRscs)
        $(msg)
        > $(rscObjects)make.opt
        -o$@
        $(appRscs)
        <
        $(RLibCmd) @$(rscObjects)make.opt
        ~time

#-----------------------------------------------------------------------
#	Builds any necessary C++ CODE modules and link them to DLL
#-----------------------------------------------------------------------
$(o)$(appName)$(oext):$(baseDir)$(appName).cpp

%include dlmlink.mki

# Blank line above required for MKE/MKI files, this line for editors that rip.

This mke file controls the generation process of the entire project, and its content is relatively complicated. Please see the next topic for a detailed introduction.

5. Right-click "Start > All Programs> Bentley > MicroStation CONNECT Edition SDK > MicroStation CONNECT Edition SDK", and select "Run as administrator" from the pop-up menu to start the MDL program development environment. After the development environment command prompt, type cd /d d:\mdlsource\helloworld and press Enter to enter the directory where our project is located, and then type bmake -a to generate HelloWorld.ma and HelloWorld.dll. These generated files are located in the …\MicroStation\mdlapps directory.

The above two commands are explained as follows:

Tips: Follow the steps in the Developer Notes section of the SDK Readme to create MicroStation CONNECT Edition SDK as a shortcut to the Windows desktop, then right-click the shortcut and select properties to open the shortcut properties, and then click the Advanced button to open the advanced property settings, check Run as administrator and press the Ok button to confirm. In the future, you can simply click this shortcut on the desktop to start the development environment.

6. Start MicroStation.exe and open any DGN file. Ensure that the current workflow in the Ribbon interface is Drawing or Modeling, then select MDL Applications under the Utilities page to open the MDL dialog box, find and select HELLOWORLD in the Available Applications list box at the bottom of the dialog box. Then click the Load button to load our MDL application. A message box with the words Hello World pops up. 

7. You need to unload the application before you rebuild any projects, otherwise you will encounter the error message shown in the figure below. The unloading method is to select HELLOWORLD in Loaded Applications at the top of the above MDL dialog box, and then click the Unload button.

Tips: You can also load and unload MDL applications by typing commands. As shown in the figure below, open the input command dialog box, enter MDL LOAD HelloWorld to load the application, and enter MDL UNLOAD HelloWorld to unload the application.

Note: MicroStation SDK development environment relies heavily on the short path of Windows (ie 8.3 format). If the disk where you installed Visual Studio or MicroStation does not support short paths, please refer to the link below to set it with FSUTIL.EXE. If you still cannot set it up, it is best to install VS and MSTN on a disk that supports short paths.

Link: https://docs.microsoft.com/en-us/archive/blogs/josebda/windows-server-2012-file-server-tip-disable-8-3-naming-and-strip-those-short-names-too 

Download Project Source Code: HelloWorld.zip. Contributed byJon Summers (LA Solutions Ltd).

Prev:[[Introduction and Prerequisites]]Next:[[Detailed Explanation of mke file]]