通过VARIANT 传递数组问题?
如题:dcom服务器是这样写的:
STDMETHODIMP ToyeImpl::Method2(VARIANT* qwe)
{
BYTE sTranMsg[120];
memset(sTranMsg, '\0', sizeof(sTranMsg));
sprintf(&sTranMsg[2], "test\0");
SAFEARRAY* psa;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = 120;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
/*for (long i = 0; i < 120; i++)
SafeArrayPutElement (psa, &i, sTranMsg ++); */
void *Dest;
SafeArrayAccessData(psa,(void**) &Dest);
memcpy( Dest , sTranMsg , 120 );
//SafeArrayPutElement()
VARIANT varBLOB;
VariantInit(&varBLOB);
V_VT(&varBLOB) = VT_ARRAY|VT_UI1;
V_ARRAY(&varBLOB)= psa;
/*VARIANT varBLOB;
OleVariant varBLOB;
varBLOB = Variant( OPENARRAY( int , ( 0 , 120 ) ) , varByte );
void *Dest = VarArrayLock( &varBLOB );
memcpy( Dest , sTranMsg , 120 );
VarArrayUnlock( &varBLOB );*/
*qwe= varBLOB;
/*BYTE sTranMsgsr[120];
long lLBound, lUBound;
SafeArrayGetLBound(varBLOB.parray, 1, &lLBound);
SafeArrayGetUBound(varBLOB.parray, 1, &lUBound);
//位图数据字节总数数
long lDataSize = lUBound - lLBound + 1;
unsigned char *pBuf = NULL;
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
memcpy(sTranMsgsr,pBuf,lDataSize);
SafeArrayUnaccessData(varBLOB.parray);*/
return S_OK;
}
//客户端是这样:
unsigned char sTranMsg[120];
memset(sTranMsg, '\0', sizeof(sTranMsg));
VARIANT varBLOB;
VariantInit(&varBLOB);
TempInterface.Method2(&varBLOB);//TempInterface 是远程接口;调用成功 可是varBLOB没变化
if(varBLOB.vt == (VT_ARRAY | VT_UI1))
{
long lLBound, lUBound;
SafeArrayGetLBound(varBLOB.parray, 1, &lLBound);
SafeArrayGetUBound(varBLOB.parray, 1, &lUBound);
//位图数据字节总数数
long lDataSize = lUBound - lLBound + 1;
unsigned char *pBuf = NULL;
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
memcpy(sTranMsg,pBuf,lDataSize);
SafeArrayUnaccessData(varBLOB.parray);
}
使用工具 c++builder 6
[解决办法]
同时安装CB5和CB6疑似有冲突吧,不过6和2009是可以共存的(除了因为路径优先引起的一些小问题)。