Click here to Skip to main content
15,885,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello world,

In my VB.net code I call a C++ dll, which should return a ouput structure.
I have a problem when the vb.net code read this structure !


The c++ structure is :

struct output_data
{
    SAFEARRAY *output1;
    SAFEARRAY *output2;
}


In the VB.net side i declare the structure like this :

Structure Output
    MarshalAs(UnmanagedType.SafeArray); Public ouput1() As String
    MarshalAs(UnmanagedType.SafeArray); Public ouput2() As String
End Structure


And the function which read the structure from the c++ dll is :

WebMethod()> _
   Public Function Test(ByRef ouput_data As Output) As Double
       Test = Cpp_Function(ouput_data)
   End Function


When i excute my soft the following exeption is raised :

System.AccessViolationException was unhandled by user code
HResult=-2147467261



Please I need your help !!
Posted
Updated 3-Jun-15 22:47pm
v2
Comments
Richard MacCutchan 4-Jun-15 7:05am    
How have you initialiased your structure before calling the CPP function?
Member 10772496 4-Jun-15 8:48am    
To initialize the array i do this :

ReDim ouput_data.ouput1(0 To 0)
ReDim ouput_data.ouput2(0 To 0)
ouput_data.ouput1(0) = 0
ouput_data.ouput2(0) = 0
Richard MacCutchan 4-Jun-15 10:08am    
And what is the CPP code trying to do?
Member 10772496 4-Jun-15 10:22am    
The C++ compute some data and complete the Safearray(BSTR) output1 and output2 in ouput structure.
Richard MacCutchan 4-Jun-15 10:44am    
Very useful information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900