Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use SAFEARRAY to return

Shulou Source: shulou.com Published: 2022-06-03 07:53:21 11月15日 Update

This article mainly introduces how to use SAFEARRAY to return, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

IDE uses VC7.1.

It's all pretty much the same at the beginning, create projects, create COM objects, create methods:

Interface definition:

[id (2), helpstring ("method GetArray")] HRESULT GetArray1 ([out,retval] VARIANT* v)

Method to realize:

STDMETHODIMP CATL3::GetArray1 (VARIANT * pvaVariant)

{

Std::vector

< float>

Vct

Vct.push_back 11.4

Vct.push_back 12.4

Vct.push_back 14.4

CComSafeArray saMatrix

For (int I = 0; I < vct.size (); + + I)

{

SaMatrix.Add (CComVariant (VCT [I]))

}

VariantInit (pvaVariant)

CComVariant var (saMatrix)

Var.Detach (pvaVariant)

Return S_OK

}

One thing to note is that to get the returned array parameters in VBS or other scripting environments, the type in the array is the VARIANT type.

VBS test script

Dim v4

Cnxn4.Add 1, 2

V4 = Cnxn4.GetArray1 ()

Dim x

For x = Lbound (v4) To Ubound (v4)

MsgBox v4 (x)

Next

Thank you for reading this article carefully. I hope the article "how to use SAFEARRAY to return" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles arrays methods types scripts similar values interests parameters and at the same time objects that is engineering interfaces more friends environment knowledge editing industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology Huawei MySQL Microsoft