Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,209 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 922 people online right now. Registration is fast and FREE... Join Now!




Calling VB.net function from C++

 
Reply to this topicStart new topic

Calling VB.net function from C++

wadem
post 16 Feb, 2008 - 02:32 PM
Post #1


New D.I.C Head

*
Joined: 16 Feb, 2008
Posts: 2

//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

User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 07:40PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month