Recently, you should use the automation component to pass the array of strings, check the MSDN-related information, or feel that it is not exhausted. It took a lot of effort to stop, (may also be insufficient levels, laughing). Close-up Next simple example, I hope to help others.
To the automated transmission array To select a Variant type, create allocated memory in the component, and release memory by the COM mechanism. So the COM customer wants to call set obj = null to clear the memory. The string of automated transmission is a BSTR type, and the selection _BSTR_T packaging class will be simpler.
Program Interpretation: Create an array, array assignment, incorporate the array into the return value.
I hope to communicate with you, please point out the mistake. Contact mail: okokex@sina.com.cn
This program is passed in VC6 and VB6. The following is the code:
StdMethod (GetArray) (/ * [out] * / variant * parray);
StdMethodimp CregWorker :: GetArray (Variant * Parray)
{
AFX_MANAGE_STATE (AFXGETSTATICModuleState ()) // Select MFC Support Auto Add
INT I;
_BSTR_T TEMP; / / # include
Pchar arrayback [] = {// Returned Array, the simplest form
"String1",
"String2",
"String3",
"String4",
String5 "
}
SafeArray * psa; // Define array descriptors
SafeArrayBound Bound [1] = {5, 1}; // One-dimensional array
PSA = SafeArrayCreate (VT_BSTR, 1, Bound); // Create an array
_Asserte (PSA! = Null);
For (i = 1; i <6; i ) {
TEMP = _BSTR_T (Arrayback [i-1]);
SafeArrayPutelement (PSA, (long *) & i, temp.copy ()); // array assignment, must be a BSTR type
}
PARRAY-> VT = VT_Array | VT_BSTR; // Variant Type Definition, BSTR type array
PARRAY-> PARRAY = PSA; // A number of incoming return values
Return S_OK;
}