Introduction

The MicroStation Development Library (MDL) and MicroStationAPI provide APIs for developers wanting to create custom applications for MicroStation® from Bentley Systems. We create a MicroStation application as a DLL, written using C++ and built with the Microsoft C++ compiler and linker provided with Visual Studio.

When editing your source code, you can choose whether to use Microsoft Visual Studio, Microsoft Visual Studio Code, or one of your favourite text editors.

When building your app, you can use Visual Studio or the Bentley Systems make (bmake) tools.

ustnTaskId

ustnTaskId is a public MicroStationAPI variable. It is used in a number of functions, such as mdlInput_sendCommand (). The MicroStationAPI mentions it a few times, but doesn't tell you how to use it.

Declaring ustnTaskId

Before you can use ustnTaskId you must declare it. You won't guess the incantation, so here it is …

BEGIN_EXTERN_C

BENTLEYDLL_EXPORT extern WCharCP      ustnTaskId;

END_EXTERN_C

Glossary of Macros

Those macros are #defined in various MicroStationAPI headers. Look in Bentley\Bentley.h for the full definition. Briefly …

Using ustnTaskId

Once you've declared ustnTaskId as shown above you can use it in your code. For example …

//  Unload the current application
mdlInput_sendCommand  (CMD_MDL_UNLOAD, mdlSystem_getCurrTaskID (),
        INPUTQ_EOQ, ustnTaskId, 0);

Linking ustnTaskId

Finally, you must link your app. with the appropriate MicroStationAPI library. Put this in your bmake file …

LINKER_LIBRARIES        + $(mdlLibs)mdlbltin.lib

Header File

We've wrapped the above in a header file. Copy the code below and save it to something like Declare_ustnTaskId_Import.h. Then include it in your source code whenever you need to use ustnTaskId …

#if !defined(DECLARE_USTNTASKID_H_INCLUDED_)
#define DECLARE_USTNTASKID_H_INCLUDED_
#pragma once

#include <Bentley/Bentley.h>

BEGIN_EXTERN_C

BENTLEYDLL_EXPORT extern WCharCP      ustnTaskId;

END_EXTERN_C

#endif	// !defined(DECLARE_USTNTASKID_H_INCLUDED_)

Acknowledgement

Thanks go to Bentley Developer Network (BDN) support staffer Robert Hook. Bob provided the necessary detail described above.

Questions

Post questions about C++ and the MicroStationAPI to the MicroStation Programming Forum.