15,896,207 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 10772496 (Top 11 by date)
Member 10772496
15-Oct-15 6:20am
View
In debugger i have also the following exception :
Raised Exception : 'System.Reflection.TargetInvocationException' dans mscorlib.dll
Member 10772496
15-Oct-15 5:27am
View
How can i catch this exception ? And in which code side (C++ or VB.net) should i do this ?
Member 10772496
8-Jun-15 4:22am
View
if it can help you, i post my code with more details.
Thanks you in advance for your help !
In the VB code i do something like :
Private Declare Function Cpp_Function Lib "XLSTATLINK.dll" (<marshalas(unmanagedtype.struct)> ByRef Input As Input_data, <marshalas(unmanagedtype.struct)> ByRef Ouput As Ouput_data) As Double
Structure Input_data
<marshalas(unmanagedtype.safearray)> Public input1() As string
<marshalas(unmanagedtype.safearray)> Public input2() As string
Public input3 As Boolean
Public input4 As Long
End Structure
<structlayout(layoutkind.sequential, pack:="8)">
Structure Ouput_data
<marshalas(unmanagedtype.safearray, safearraysubtype:="VarEnum.VT_BSTR)"> Public ouput1() As String
End Structure
<webmethod()> _
Public Function Test(ByRef Input As Input_data, ByRef Ouput As Ouput_data) As Double
ReDim Ouput.ouput1(0 To 0)
Ouput.ouput1(0) = 0
test = Cpp_Function(Input, Ouput)
End Function
And my C++ code is something like :
#pragma pack(push, 8)
struct DCA_input_data
{
SAFEARRAY *input1;
SAFEARRAY *input2;
VARIANT_BOOL input3;
long input4;
};
struct DCA_output_data
{
SAFEARRAY *ouput1;
SAFEARRAY *ouput2;
};
#pragma pack(pop) //back to whatever the previous packing mode was
void ArrayToSafearrayCopy(BSTR *array, SAFEARRAY *&safeArray)
{
int moLenght = 0;
do
{
moLenght++;
} while (array[moLenght] != nullptr);
// Create a safe array of BSTR
CComSafeArray<bstr> saData(moLenght);
for (int i = 0; i < moLenght; i++)
{
saData[i] = array[i];
}
safeArray = saData.Detach();
saData.Destroy();
}
Test_API double __stdcall Cpp_Function(Input_data *pInput, Output_data *pOutput)
{
BSTR *mInput1 = LoadSAFEARRAYStr(&pInput->input1); // convert the SafeArray table into a BSTR table
BSTR *mInput2 = LoadSAFEARRAYStr(&pInput->input2); // convert the SafeArray table into a BSTR table
BSTR *moInput1;
BSTR *moInput2;
...
...
...
//Some computation on mInput1 and mInput2 ... and results are store in moInput1 and moInput2
...
...
...
ArrayToSafearrayCopy(moInput1, pOutput->ouput1);
ArrayToSafearrayCopy(moInput2, pOutput->ouput2);
}
For you information, I done some tests in my side :
1) When I send only the input data, i have no problems !
2) I checked the C++ code with a VBA test code, i have no problem !
Member 10772496
4-Jun-15 11:33am
View
The objectif of the vb.net code is to read the contained of the structure completed by the C++ DLL.
But When I try to read the ouput_data in the VB.net side, the System.AccessViolationException exception is raised.
I think my problem is that a don't use correctly the marshalling of the structure composed of SAFEARRAY coming from the C++ DLL.
What should i do to make this correctly ?
Member 10772496
4-Jun-15 10:50am
View
The C++ just complete the ouput_data structure ...
What you wanted more ?
Member 10772496
4-Jun-15 10:22am
View
Deleted
The C++ compute some data and complete the Safearray(BSTR) output1 and output2 in ouput structure.
Member 10772496
4-Jun-15 10:22am
View
The C++ compute some data and complete the Safearray(BSTR) output1 and output2 in ouput structure.
Member 10772496
4-Jun-15 8:49am
View
Ok sorry, to initialize the array i do this :
ouput_data.ouput1(0) = 0
ouput_data.ouput2(0) = 0
Member 10772496
4-Jun-15 8:48am
View
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
Member 10772496
4-Jun-15 7:35am
View
Deleted
Ok sorry, to initialize the array i do this :
DCA_ouput_data.ouput1(0) = 0
DCA_ouput_data.ouput2(0) = 0
Member 10772496
4-Jun-15 7:14am
View
Yes before calling the C++ function, i have initialized the structure in vb.net code.
ReDim ouput_data.ouput1(0 To 0)
ReDim ouput_data.ouput2(0 To 0)
Show More