Hi,
I'm looking to call mdlCell_create from my C# addin, I've implimented the VBA decleration but stuck on how to call it. Any thoughts welcome. Alternativly can anyone give me some guidence on how to call this in a VBA environment?
[DllImport("stdmdlbltin.dll")]
public extern static void mdlCell_Create(int cellElm, int cellName, Point3d origin, int pointCell);
based on
Declare Function mdlCell_create Lib "stdmdlbltin.dll" (ByVal cellElm As Long, ByVal cellName As Long, ByRef origin As Point3d, ByVal pointCell As Long) As Long
Thanks,
Mike
Michael Laws said:I'm looking to call mdlCell_create from my C# addin
You're using MicroStation V8i. You can call the VBA methods through an InterOp quite easily. Why do you feel the need to use MDL?
Michael Laws said:Declare Function mdlCell_create Lib "stdmdlbltin.dll" (ByVal cellElm As Long, ByVal cellName As Long, ByRef origin As Point3d, ByVal pointCell As Long) As Long
It's not easy to use MDL functions that require pointers from other languages that don't have pointer support. In this case the first argument cellElm is a pointer-to-pointer. How does C# deal with that? What does that MDL function provide that VBA doesn't?
cellElm
Regards, Jon Summers LA Solutions
I'm trying to avoid the issue of com memory not releasing until the process is closed.
I've considered a MDL addin but we have a large number of .NET libraries built up. I guess the solution would be to build a C++ wrapper to then call in C#. It's possible to use pointers in C# through use of the unsafe decleration, and similarly in VBA with VarPtr so thought it'd be possible to do a direct call to this function.
As always, thanks for the fast response Jon.
HI Michael,
Michael Laws said:I'm trying to avoid the issue of com memory not releasing until the process is closed.
Do you have any reference about this issue? I have not too much experience with COM programming, but I have never heared about such condition when COM/Interop is used from NET.
Michael Laws said:It's possible to use pointers in C# through use of the unsafe decleration
Yes, it's possible, but it's treated as bad practice as far as I know. There are some consequences how code can be optimized and in my opinion it makes the code less maintenable.
Michael Laws said:I guess the solution would be to build a C++ wrapper to then call in C#.
If you do not want to use Interop API available in MicroStation addin or you need to use anything available in C/C++ API only, to use C++/CLI to create own wrappers is recommended. To use just a few calls to C (using e.g. P/Invoke) is fine, but when a number of such calls grows, C++/CLI is the way to go.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Michael Laws said:I'm trying to avoid the issue of com memory not releasing until the process is closed
Use explicit delete in VBA:
Set oSomething = Nothing
Using MDL, you've introduced the problem of not releasing C-allocated memory (there's a hidden malloc() in mdlCell_Create(). You must explicitly delete that allocated memory at the appropriate time.
malloc()
mdlCell_Create()