CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Threaded View

  1. #1
    Join Date
    Oct 2010
    Posts
    44

    Question C++ Wrapper for VB.net

    Hello Guru's:

    I am trying to create a wrapper for C++ dll using a vb.net. I have manage to create a wrapper but upon calling the function
    I have encounter a error: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt"

    Below is my code in importing the c++ dll


    Code:
    Imports System.Runtime.InteropServices
    
    Public Class MYWrapper    
        <DllImport("MYtest.dll", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi)>
        Public Shared Sub Reset(ByVal sSection As [String], ByVal lResult As Int32)
        End Sub    
        <DllImport("MYtest.DLL", EntryPoint:="Init", SetLastError:=True, _
            CharSet:=CharSet.Ansi, ExactSpelling:=True, _
            CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Sub Init(ByVal objectInstanceName As String, ByVal sPath As String, ByVal sSection As String, ByVal sTestPlanRevision As String, ByRef lResult As Int32)
        End Sub
    End Class
    C++ Header
    Code:
    extern "C" MY_API void Reset  (const char *sSection, long &lResult);
    extern "C" MY_API void Init     (const char *sObjectInstanceName, const char *sPath, const char *sSection, const char *sTestplanRevision, long &lResult);

    VB.net Program
    Code:
     Dim IResult As Int32
    
            Const sOjectname As String = "C:\confg.cfg"
            Dim sError As String
            Const sProductConf As String = "Config.cfg"
            Const sOperation As String = "TEST0001"
            Const sTPRev As String = "V1"
    
            Try
                MYWrapper.Wrapper.Init(sOjectname, sProductConf, sOperation, sTPRev, IResult)
            Catch ex As Exception
                sError = ex.Message.ToString()
            End Try
    Regards,
    Newbie here
    Last edited by kpax1684; August 29th, 2014 at 06:55 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured