STDMETHODIMP
CWinSockIPv6::
SendTo( SAFEARRAY** buf, VARIANT len, LONG* bytesSent)
{
LONG lBound, uBound;
LONG length;
SafeArrayGetLBound( *buf, 1, &lBound);
SafeArrayGetUBound( *buf, 1, &uBound);
length = uBound - lBound + 1;
if ( len.vt == VT_ERROR && len.scode == DISP_E_PARAMNOTFOUND)
{
; // 这样 length = 默认值
}
else
{
if ( len.vt != VT_I4 )
VariantChangeType( &len, &len, 0, VT_I4);
if ( len.lVal > length ) // 要发送的数据,怎么可以比 length 还多呢?
return S_FALSE;
else
length = len.lVal;
}
char* p;
SafeArrayAccessData( *buf, (void HUGEP**)&p );
*bytesSent = CWinSockIPv6Internel<CWinSockIPv6>::sendto( p, length);
SafeArrayUnaccessData(*buf);
return S_OK;
}
STDMETHODIMP
CWinSockIPv6::
GetData( SAFEARRAY** buf, LONG* bytesGet)
{
if( *buf != NULL ) {
SafeArrayDestroy( *buf );
*buf = NULL;
}
* bytesGet = 0;
if ( recv_length_ == 0)
return S_OK;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = recv_length_;
*buf = SafeArrayCreate( VT_UI1, 1, rgsabound);
if ( *buf == NULL)
return E_OUTOFMEMORY;
HUGEP void * p;
SafeArrayAccessData( *buf, (void HUGEP * FAR *)&p );
memcpy( p, recv_buffer_, recv_length_);
SafeArrayUnaccessData(*buf);
* bytesGet = recv_length_;
return S_OK;
}