I am new to COM, and I think I have it right, but the runtime is not like it. Any help is greatly appreciated.
I need to call a COM function that takes a one-dimensional BSTR array. In particular, the documentation states that the parameter should be:
Function: AddFiles ([in] VARIANT * filePaths)
filePaths A single array of full paths to each file or folder. filePaths can be of type VT_ARRAY|VT_VARIANTwhere each entry is VT_BSTRor VT_ARRAY|VT_BSTR.
I have vector<wstring> myPathspaths that I want to pass to a function that takes the parameter above. Here is the code I wrote. Calling AddFiles on myComObject results in AV (myComObject is not null, and I can call other methods on it):
...
VARIANT filePaths;
VariantInit( &filePaths );
filePaths.vt = VT_ARRAY|VT_VARIANT;
filePaths.parray = SafeArrayCreateVector( VT_BSTR, 0, (unsigned int) myPaths.size() );
long i = 0;
for( vector<wstring>::iterator it = myPaths.begin();
it != myPaths.end();
it++, i++ )
{
BSTR myPath= SysAllocString(it->c_str());
SafeArrayPutElement( filePaths.parray, &i, myPath);
}
myComObject->AddFiles( &filePaths );
...
COM- , , , - AddFiles , , - ?