VB通过com方式传递数组给c++ 使用VARIANT变量

STDMETHODIMP CMXRender::FillPolygon(VARIANT pts,LONG* res)
{
// TODO: 在此添加实现代码
if(pts.vt != (VT_ARRAY|VT_DISPATCH) ||m_GeoRender == NULL)
return S_FALSE;
LPSAFEARRAY parr
= pts.parray;
LONG count
= 0;
if(SafeArrayGetDim(parr) == 1 &&SafeArrayGetUBound(parr, 1, &count) == S_OK)
{
PointF
*points = new PointF[count];
if(points == NULL)
return S_FALSE;
for(LONG i = 0; i < count; i++)
{
void *fs = NULL;
if(SafeArrayGetElement(parr, &i,static_cast<void *>(&fs))!=S_OK)
return S_FALSE;
IDispatch
*ifs= (IDispatch *)fs;
CMXPixel
* out ;
HRESULT hr
= ifs->QueryInterface(IID_IMXPixel,(void**)&out);
if (SUCCEEDED(hr))
{
points[i].X
= out->m_point.x;
points[i].Y
= out->m_point.y;
}

}
*res = m_GeoRender->FillPolygon(points,count);
delete []points;
}
return S_OK;
}
 

用于转换的部分已经用红色标出

下边的QueryInterface是用来判断传进来的IDispatch 是不是包含我所需要的接口因为强制转换不同的IDispatch 肯定会报错

posted @ 2011-08-11 15:27  银翼的魔术师  阅读(516)  评论(0编辑  收藏  举报