passing Safearray to VB

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: haglu (tfa613_at_yahoo.de)
Date: 09/04/04


Date: 4 Sep 2004 06:50:07 -0700

Hello,
I try to pass an array of BSTR to a VB client. When the VB procedure
exits, I get a Firstchance Exception in the Server. I think there is
anything wrong with the memory allocation (Windbg output: ...
ole32!CoTaskMemFree ...). ???? But I cant find the mistake.
Can anybody help?

idl:
HRESULT GetComponentNames([in]BSTR bstrFileName, [out,retval] VARIANT*
pNamesArray);
------------------------------------------------------
CPP Server:
HRESULT CExperiment::GetComponentNames(BSTR bstrFileName, VARIANT*
pNamesArray)
{
        SAFEARRAYBOUND rgaBound[1];
        rgaBound[0].lLbound=0;
        rgaBound[0].cElements = m_ComponentNames.size();
        
        ReadFile(bstrFileName); // read m_ComponentNames

        VariantInit(pNamesArray);
        pNamesArray->vt = VT_ARRAY|VT_BSTR;
        pNamesArray->parray = SafeArrayCreate(VT_BSTR,1,rgaBound);
        if (pNamesArray->parray == NULL)
        { // allocation failed
                return(E_OUTOFMEMORY);
        }
        
        long i = 0;
        for (iter = m_ComponentNames.begin();iter!=m_ComponentNames.end();iter++
)
        {
                CComBSTR bstr = iter->c_str();
                SafeArrayPutElement(pNamesArray->parray,&i, bstr);
                i++;
        }
        
        return S_OK;
}

------------------------------------------------------
VB Client:
Public Sub UpdateComponentNames()
    Dim Experiment As NIRExperiment
    Dim strNames() As String
    
    Dim i As Integer
    
    On Error GoTo err
    Set Experiment = GetExperiment
    strNames = Experiment.GetConstituentNames(m_strFileName)
    ' update names
    ......
Exit sub



Relevant Pages

  • Re: MAC Address
    ... Note that the IP address of the client is not reliable ... MAC addresses on the computer on which the code resides, but the server ... Dim SessionID As Int32 'DWORD integer ... ByVal SessionId As Int32, ByVal WTSInfoClass As Int32, ...
    (microsoft.public.windows.terminal_services)
  • Re: Using Visual Basic NET to Access Terminal Services Session and Client Information
    ... It also accesses the Client Information for the client which executes ... this program on a Terminal Services Server. ... Dim pWinStationName As String ' integer LPTSTR - Pointer to a null-terminated string containing the name of the WinStation for this session ... ByVal SessionId As Int32, ByVal WTSInfoClass As Int32, ByRef ppBuffer As String, ByRef pCount As Int32) As Boolean ...
    (microsoft.public.windows.terminal_services)
  • Using Visual Basic NET to Access Terminal Services Session and Client Information
    ... It also accesses the Client Information for the client which executes this program on a Terminal Services Server. ... Dim pWinStationName As String ' integer LPTSTR - Pointer to a null-terminated string containing the name of the WinStation for this session ...
    (microsoft.public.windows.terminal_services)
  • passing Safearray to VB
    ... I try to pass an array of BSTR to a VB client. ... exits, I get a Firstchance Exception in the Server. ... Dim Experiment As NIRExperiment ...
    (microsoft.public.vc.atl)
  • Re: Socket.Receive hangs
    ... client to a server and receives messages in return. ... functionality is made with sockets which is working just fine except of ... Dim oRemoteEndPoint As New System.Net.IPEndPoint ...
    (microsoft.public.dotnet.languages.vb)