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
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.
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
Those macros are #define
d in various MicroStationAPI headers.
Look in Bentley\Bentley.h
for the full definition.
Briefly …
BEGIN_EXTERN_C
and END_EXTERN_C
bracket statements that you want to declare extern "C"
.
They save some typing
BENTLEYDLL_EXPORT
is shorthand for __declspec(dllimport)
extern
is standard C++, indicating that a variable is declared externally to the current code module
WCharCP
is a typedef
for wchar_t const*
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);
Finally, you must link your app. with the appropriate MicroStationAPI library. Put this in your bmake file …
LINKER_LIBRARIES + $(mdlLibs)mdlbltin.lib
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_)
Thanks go to Bentley Developer Network (BDN) support staffer Robert Hook. Bob provided the necessary detail described above.
Post questions about C++ and the MicroStationAPI to the MicroStation Programming Forum.