Trouble using COM Server that need VARIANT* from VB.NET
I have an ATL COM Server that need to return a lot of data. To accomplish this task the COM Server use an argument of type VARIANT*.
With VB6 we haven't problems, the server works properly. Using the same componente with VB.NET we are not able to pass an Array or an Object by reference. The COM Server method fails because the data is always VT_EMPTY or is notVT_BYREF.
This is dependent from MIDL definition.
// MIDL --
[id(6), helpstring("method ResponseArray")] HRESULT ResponseArray([out] LONG* Slave, [out] LONG* Function, [out] LONG* Count, [in,out] VARIANT* TelegramData, [in] LONG WaitTime);
Server get VT_EMPTY// MIDL --
[id(6), helpstring("method ResponseArray")] HRESULT ResponseArray([out] LONG* Slave, [out] LONG* Function, [out] LONG* Count, [out] VARIANT* TelegramData, [in] LONG WaitTime);
Server get VT_ARRAY | VT_UI1 but SAFEARRAY pointer is invalid!In order to describe the test conditions i have also included some parts of source to describe the environment. // Server -
STDMETHODIMP CModBusConnection::ResponseArray(LONG* Slave, LONG* Function, LONG* Count, VARIANT* TelegramData, LONG WaitTime){
if( m_pModBus == NULL )
return E_ACCESSDENIED;
if( !m_pModBus->Connected() )
return E_ABORT;
if( TelegramData == NULL ){
ATLASSERT( TelegramData != NULL );
return E_INVALIDARG;
}
if( TelegramData->vt != (VT_BYREF | VT_ARRAY | VT_UI1)) {
ATLASSERT( TelegramData->vt == (VT_BYREF | VT_ARRAY | VT_UI1) ) ;
return E_INVALIDARG;
}
long Dims = SafeArrayGetDim(*TelegramData->pparray);
if( Dims !=1 )
return E_INVALIDARG;
long LowerBounds,UpperBounds;
if( FAILED(SafeArrayGetLBound(*TelegramData->pparray,1,&LowerBounds)) )
return E_FAIL;
if( FAILED(SafeArrayGetUBound(*TelegramData->pparray,1,&UpperBounds)) )
return E_FAIL;
if( LowerBounds <0 || UpperBounds <1024 )
return E_INVALIDARG;
....
// Client -
VB.NET CODE
PrivateSub btnReadRegisters_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btnReadRegisters.Click
Dim RxSlaveAsLong
Dim RxFunctionAsLong
Dim RxByteCountAsLong
Dim ErrorCodeAsLong
Dim DataBuf(1024)AsByte
Any help would be appreciated.
Thanks

