
CString SelectElement2(SAFEARRAY * iFilterType, BSTR * iMessage, BOOL iObjectSelectionBeforeCommandUsePossibility)
{
CString result;
static BYTE parms[] = VTS_NONE VTS_PBSTR VTS_BOOL ;
InvokeHelper(0x60050013, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms, iFilterType, iMessage, iObjectSelectionBeforeCommandUsePossibility);
return result;
}
{
CString result;
static BYTE parms[] = VTS_NONE VTS_PBSTR VTS_BOOL ;
InvokeHelper(0x60050013, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms, iFilterType, iMessage, iObjectSelectionBeforeCommandUsePossibility);
return result;
}
在这里,我需要用SAFEARRAY *传递一个"Vertex"的string到该函数使用。
目前使用的函数是这样的:

//用VARIANT先封装BSTR,再用微软的方法进行转换
//首先用SAFEARRAY包装一层
SAFEARRAYBOUND bound[1];
bound[0].lLbound=0;
bound[0].cElements=1;
SAFEARRAY *psa =SafeArrayCreate(VT_BSTR,1,bound);
BSTR bFilter;
bFilter =SysAllocString(L"Vertex");
LONG i=0;
SafeArrayPutElement(psa,(long*)&i,bFilter);
VARIANT FAR VBpStrArray;
VariantInit(&VBpStrArray);
VBpStrArray.vt=VT_ARRAY|VT_BSTR;
VBpStrArray.parray = psa;
SAFEARRAY FAR *pStrArrTemp = NULL;
long LBound;
long UBound;
BSTR HUGEP *pbstr;
CString strtemp;
USES_CONVERSION;
pStrArrTemp = V_ARRAY(&VBpStrArray);
SafeArrayGetLBound(pStrArrTemp,1,&LBound);
SafeArrayGetUBound(pStrArrTemp,1,&UBound);
SafeArrayAccessData(pStrArrTemp, (void HUGEP* FAR*)&pbstr);
for (int i=0;i<(UBound-LBound);i++)
strtemp+=LPWSTR(pbstr);
cstrStatus = selSelection.SelectElement2(pStrArrTemp,NULL,FALSE);
//首先用SAFEARRAY包装一层
SAFEARRAYBOUND bound[1];
bound[0].lLbound=0;
bound[0].cElements=1;
SAFEARRAY *psa =SafeArrayCreate(VT_BSTR,1,bound);
BSTR bFilter;
bFilter =SysAllocString(L"Vertex");
LONG i=0;
SafeArrayPutElement(psa,(long*)&i,bFilter);
VARIANT FAR VBpStrArray;
VariantInit(&VBpStrArray);
VBpStrArray.vt=VT_ARRAY|VT_BSTR;
VBpStrArray.parray = psa;
SAFEARRAY FAR *pStrArrTemp = NULL;
long LBound;
long UBound;
BSTR HUGEP *pbstr;
CString strtemp;
USES_CONVERSION;
pStrArrTemp = V_ARRAY(&VBpStrArray);
SafeArrayGetLBound(pStrArrTemp,1,&LBound);
SafeArrayGetUBound(pStrArrTemp,1,&UBound);
SafeArrayAccessData(pStrArrTemp, (void HUGEP* FAR*)&pbstr);
for (int i=0;i<(UBound-LBound);i++)
strtemp+=LPWSTR(pbstr);
cstrStatus = selSelection.SelectElement2(pStrArrTemp,NULL,FALSE);
运行到这里的时候,显示 类型不匹配。添加监视窗口,发现SAFEARRAY里面已经存了“Vertex"这个string.
实在找不到解决办法了,希望能得到大家的指点.
[ 本帖最后由 HeyjohnLin 于 2015-6-16 21:18 编辑 ]