Hi all
I have a large VBA project that worked on V8i that I need to transfer to Connect. I've manage to sort out a lot of issues so far, but I am a bit stuck on this one.
ActiveSettings.DimensionStyle.AnnotationScale = (mdlModelRef_getEffectiveAnnotationScale(ActiveModelReference.MdlModelRefP))
The MdlModelRefP creates a mismatch error. Has anyone dealt with a similar issue that might help point me in the right direction? Or an alternative way to get the annotation scale?
I'm on Version 10.16.01.56
Thanks in advance.
Declare PtrSafe Function mdlModelRef_getEffectiveAnnotationScale Lib "stdmdlbltin.dll" (ByVal modelRefIn As Long) As Double
Thanks
Ok ... that's probably the source of the problem. Did you read MicroStation VBA help, namely Changes for VBA 7.1 chapter?
From the documentation: An existing declaration that declares all pointers as Long will not work reliably in a 64-bit process. It will compile correctly but is very likely to cause a crash. It may crash the first time it is used, or it may just crash intermittently. To help programmers cope with this, Microsoft introduced the keyword PtrSafe.
Because the native function is declared as double mdlModelRef_getEffectiveAnnotationScale (DgnModelRefP modelRefIn) , I think you have to use, accordingly to VBA documentation, not Long for pointers (as was in V8i), but PtrSafe type.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: Michael Reilly
Thanks Jan,
(ByVal modelRefIn As LongLong)
Why you prefer to use LongLong and not, as recommedend, PtrSafe (or LongPtr)? It does not work?
To use LongLong to pass pointers is correct in terms of "bitness", but incorrect semantically, because even when pointer is 64bit number, it is not number, but type pointer. It is reason why LongPtr (64bit pointer) and PtrSafe (pointer with assertion) exist in VBA.
You declaration now tells "I pass 64bit number", which is not correct, because you pass 64bit pointer.
See this Microsoft article for details.
With regards,