I'd like to know about SAFEARRAY implementation.
It seems to me that there's no field in SAFEARRAY structure that is used for storing element type information, such as VT_I4(3) or VT_R4(4), but SafeArrayGetVartype function returns the correct type.
Somebody commented on the MSDN page below saying that the high word of the cLocks holds the type info: SAFEARRAY structure on MSDN
But when I passed Long and Single arrays from VBA to a DLL function via a type libray, those arrays' fFeatures are both 0x80, cLocks are both 0, and stll SafeArrayGetVartype can tell VT_I4(3) and VT_R4(4).
Depending on how the safearray was created, the variant type may be stored in memory before (at the offset -4 from the start of) the
SAFEARRAYstructure.FADF_HAVEVARTYPEflag infFeaturesindicates whether the type is available.Similarly,
FADF_HAVEIIDindicates that the GUID (seeSafeArrayCreateEx) is stored at offset of -16, and available viaSafeArrayGetIID.FADF_HAVEVARTYPEandFADF_HAVEIIDcan never be present simultaneously (because otherwise theVARTYPEand theGUIDwould overlap in memory), butSafeArrayGetVartypeis smart enough to synthesize one ofVT_RECORD,VT_DISPATCHorVT_UNKNOWNtypes when it sees corresponding feature flags.