How to pass an array for COM parameters

xiaoxiao2021-03-06  38

It seems that there are few arrays in the parameters of COM. But sometimes the array does have its convenience. In particular, variant arrays can store different data types, particularly convenient. (There is also the use of variant arrays, very useful), such as now there is a pile of data, and the branch condition for processing is the type of data.

Call code in VB:

DIM VAR1, VAR2redim var1 (3) var1 (0) = CINT (10) 'Integer requirement * 10var1 (1) = CLNG (10)' long integer requires * 100VAR1 (2) = CSTR (10) 'string required Add a prefix: string: var2 = com.handle (var1)

The processing of OLE in Windows contains the processing of the array, but it is very troublesome. Fortunately, the VC is packaged, and ColesafeArray can be well processed. The processing of the VC is as follows: (using MFC) Variant CCOMARRAYHANDLE :: Handle Sainput (var); COLESAFEARRAY SAINPUT (VAR); long index [1], l, u; sainput.getlbound (1, & l); SAINPUT .Getubound (1, & U); DWORD NUMELEMENTS [] = {ABS (UL)}; Saret.create (VT_VARIANT, 1, Numelements); For (Index [0] = L; Index [0]

转载请注明原文地址:https://www.9cbs.com/read-69202.html

New Post(0)