这是一个基于 Remy用 AutoHotkey 编写的解决方案的原型:
VariantVector := [{vt:0x001F, val:"hello world"}, {vt:0x0003, val:3}]
VarSetCapacity(PropVariant, 8 + 2 * A_PtrSize, 0)
InitPropVariatFromVariantAsVector(PropVariant, VariantVector)
; Do something here...
PropVariantClear(PropVariant)
return
InitPropVariatFromVariantAsVector(ByRef PropVariant, VariantVector) {
static VT_VARIANT := 0x000C
static VT_VECTOR := 0x1000
static Size := 8 + 2 * A_PtrSize
NumPut(VT_VARIANT | VT_VECTOR, PropVariant, 0, "UShort")
NumPut(VariantVector.Count(), PropVariant, 8, "UInt")
ptr := DllCall("Ole32\CoTaskMemAlloc", "UPtr", Size * VariantVector.Count(), "Ptr")
NumPut(ptr, PropVariant, 8 + A_PtrSize, "Ptr")
for Each, Variant in VariantVector {
Offset := Size * (Each - 1)
NumPut(Variant.vt, ptr + 0, Offset, "UShort")
Switch Variant.vt
{
Case 0x0003: NumPut(Variant.val, ptr + 0, Offset + 8, "Int") ; VT_I4
Case 0x001E: DllCall("Shlwapi\SHStrDup", "AStr", Variant.val, "Ptr", ptr + Offset + 8, "Int") ; VT_LPSTR
Case 0x001F: DllCall("Shlwapi\SHStrDup", "WStr", Variant.val, "Ptr", ptr + Offset + 8, "Int") ; VT_LPWSTR
Default: throw Exception(A_ThisFunc ": Unsupported Variant Type.", -1, Format("0x{:04X}", Variant.vt))
}
}
}
PropVariantClear(ByRef PropVariant) {
return DllCall("Ole32\PropVariantClear", "Ptr", &PropVariant, "Int")
}