//I am trying to call the VB.Net code from the C++ code using the
_stdcall convention
CODE
#include "stdafx.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
#ifdef _MANAGED
#pragma managed(pop)
#endif
#using "C:\_Wade\Projects\SetFile\ReadSetFile\ReadSetFile\bin\Release\ReadSetFile.dll"
__declspec(dllexport) char* __stdcall OpenDB(char* name)
{
int i = 0;
while (*name != '\0')
{
i++;
name++;
}
array<unsigned char>^ nameManArr =
gcnew array<unsigned char>(i);
name -= i;
i = 0;
while (*name != '\0')
{
nameManArr[i] = *name;
name++;
i++;
}
array<unsigned char>^ char8ManArr = OpenDB(nameManArr);
char* char8UnmanArr = new char[char8ManArr->Length + 1];
for (int i = 0; i < char8ManArr->Length; i++)
{
char8UnmanArr[i] = char8ManArr[i];
}
char8UnmanArr[char8ManArr->Length] = '\0';
return char8UnmanArr;
}
[b]//VB.NET Code below[/b]
Imports System.Data.OleDb
'
Public Class SetFile
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Public Function OpenDB(ByVal DBLocation As String) As String
'provider to be used when working with access database
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBLocation & ";")
cn.Open()
'Return (cn.State)
Return (DBLocation)
End Function
Public Function ReadData(ByVal myPair As String) As Long
cmd = New OleDbCommand("select * from SetFile where Pair='" & myPair & "'", cn)
dr = cmd.ExecuteReader
'While dr.Read()
Return (dr.RecordsAffected)
' loading data into TextBoxes by column index
'End While
'Catch
'End Try
End Function
Public Function GetData(ByVal FieldName As String) As String
Try
Return (dr(FieldName))
Catch ex As Exception
Return ("")
End Try
End Function
Public Function CloseDB() As Boolean
dr.Close()
cn.Close()
End Function
End Class