Yongan.Fu:
ElementID is not a structure, it is just a base type __int64
Correct — but only for MDL and C++, which support the __int64 data type. Microsoft invented VBA before 64-bit processors existed and does not support the 64-bit integer data type, which is why Bentley Systems invented the DLong UDT. MDL's ElementID is an alias for __int64.
The problem is this …
ElementID id = 0;
mdlSheetDef_getBorderAttachmentId (..., &id);
In the above fragment, the variable that contains the element ID (a 64-bit number) is passed by address. C/C++ languages work can modify the contents of an address. It's the equivalent of VBA ByRef. However, because VBA can't cope with 64-bit integers, we have to use the DLong UDT. In this case the MDL wrapper declaration from MDL help is correct …
Declare Function mdlSheetDef_getBorderAttachmentId _
Lib "stdmdlbltin.dll" ( _
ByVal sheetDefIn As Long , _
ByRef borderAttachmentIdOut As DLong ) As Long
The MDL wrapper for the setter function is incorrect, because it wants to pass a DLong by value …
Declare Function mdlSheetDef_setBorderAttachmentId _
Lib "stdmdlbltin.dll" ( _
ByVal sheetDefIn As Long , _
ByVal borderAttachmentIdIn As DLong ) As Long
We can edit that declaration so that VBA will parse it correctly …
Declare Function mdlSheetDef_setBorderAttachmentId _
Lib "stdmdlbltin.dll" ( _
ByVal sheetDefIn As Long , _
ByRef borderAttachmentIdIn As DLong ) As Long
However, changing that declaration does not change the underlying code. We don't know how that MDL wrapper is implemented. I suspect that there may be some internal confusion in the conversion from the internal __int64 and the VBA DLong passed by address.
Regards, Jon Summers
LA Solutions