MicroStation CONNECT continues to use public global variables. The one that interests me at the moment is mgds_modes. It's defined in header file MicroStation.r.h and declared extern in dloadlib.h.
mgds_modes
MicroStation.r.h
extern
dloadlib.h
With C++, I can use such a variable simply by including those header files and linking with the appropriate library. How do I use a C++ global variable when writing a .NET AddIn?
Hi Jon,
Jon Summers said:How do I use a C++ global variable when writing a .NET AddIn?
I think you have to use the same approach as for an access of C++ API: To use P/Invoke or C++/CLI and to implement own wrapper.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jon Summers,
Primarily for legacy published variable access from .NET addins the cleanest implementation would be calling GetCExpression/SetCExpression via Bentley.Interop.MicroStationDGN.Application (MicroStation VBA COM wrappers). Next would be as Jan suggestions C++/CLI helper methods that could provide similar clean calling conventions and better performance.
Lastly, though more work required and fewer code snips/examples available, either: EC (IECInstance > IECSchema > IECClass StringValue) or BIM.NamedExpressionManager (see this post) permit you to access and/or publish via NamedExpressions.
HTH,Bob
[UPDATE-20210510-RH] MSCE SDK provides a v0811 NamedExpression example under: ..\Documentation\Migration\Workshop\Labs\MigrationTesting\v0811\dotnet\examples\NamedExprTest\NamedExprApp.cs
Answer Verified By: Jon Summers
Jan Ĺ legr said:I think you have to use the same approach as for an access of C++ API: To use P/Invoke
There is no way I can find to use P/Invoke with a global variable.
Jan Ĺ legr said: Use C++/CLI and to implement own wrapper
That seems arduous simply to find the value of a global integer variable. But it may be my only recourse.
Regards, Jon Summers LA Solutions
Robert Hook said:The cleanest implementation would be calling GetCExpression/SetCExpression
Thanks for that suggestion. The C expression parser enables read/write access to C++ global var mgds_modes.always_open_readonly.
mgds_modes.always_open_readonly
You're welcome and glad it helped.
Bob