I'm a COM newbie and I think what I have is correct, but the runtime doesn't like it. Any help is much appreciated.
I need to invoke a COM function that takes in a single dimensional array of BSTRs. Specifically, the documentation says the parameter must be:
Function: AddFiles ( [in] VARIANT * filePaths )
filePaths The single-dimensioned array of full paths to each file or folder. filePaths can be of type
VT_ARRAY|VT_VARIANT
, where each entry is aVT_BSTR
, orVT_ARRAY|VT_BSTR
.
I have a vector<wstring> myPaths
of paths which I want to pass into the function that takes the parameter above. Here's the code I wrote. Calling AddFiles on myComObject results in an AV (myComObject is not null, and I can invoke 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 );
...
The COM object isn't my code and I can't debug into it, but I suspect I'm not creating that array properly - based on the requirement of the AddFiles function and the code I have, anyone have ideas about what I might be doing wrong?