Sorry, it's my fault (plus doc's fault).
In MDL side, mdlSheetDef_getBorderAttachmentId use ElementID * as its second parameter but mdlSheetDef_setBorderAttachmentId use ElementID as it. Using declaration ByVal borderAttachmentId As DLong is ok for mdlSheetDef_getBorderAttachmentId but not ok for mdlSheetDef_setBorderAttachmentId.
I will investigate this interesting question further and find a Bentley expert to help.
YongAn