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