How To: C++ DLL function returns Structure Array to VB .NET

L

lov4mu6

Hello,

I have a DLL that I've compiled in Visual C++ which I'm referencing in
VB .NET

The function in the DLL returns a simple structure array. I need to be
able to capture this structure array in VB .NET.

C++ code:
struct NotesInfo
{
int Note;
int StartTime;
int EndTime;
};

NotesInfo mytest(char *fHMM, char *fWaveUserQuery)
{
NotesInfo *Score;
Score = new NotesInfo[2];

Score[0].StartTime = 0;
Score[0].EndTime = 1;
Score[0].Note = 60;

Score[1].StartTime = 2;
Score[1].EndTime = 3;
Score[1].Note = 70;

return *Score;
}

above code compiles into DLL.


In VB.NET, I have coded the same structure:
Structure ScoreData
Dim Note AS Integer
Dim StartTime AS Integer
Dim EndTime AS Integer
End Structure

This is how I reference the DLL in VB .NET:
Private Declare Function mytest Lib "C:\MyLib.dll" (ByVal FileTrainData
As String, ByVal FileWaveUsrQuery AS String) AS IntPtr

I'm not sure if I need to declare mytest function as IntPtr or as
ScoreData? Either way, I need to be able to capture the structure array
output from the DLL and assign it to the structure in VB .NET

Any suggestions are greatly appreciated!
Vlad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top