-
August 28th, 2014, 06:53 AM
#1
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.
-
August 28th, 2014, 07:19 AM
#2
Re: C++ Wrapper for VB.net
Please, edit your post to add the Code tags around the code snippets. Otherwise your code is absolutely unreadable!
Victor Nijegorodov
-
August 28th, 2014, 02:23 PM
#3
Re: C++ Wrapper for VB.net
Do the dll functions work when called from a C++ test project?
-
August 29th, 2014, 03:42 AM
#4
Re: C++ Wrapper for VB.net
Hello Arjay:
YES is 100% working when it is being called in the C++ test project.. I don't have the source code of this c++ dll, I only have the DLL and a .H header.
Regards,
Newbie here
Originally Posted by Arjay
Do the dll functions work when called from a C++ test project?
-
August 29th, 2014, 03:42 AM
#5
Re: C++ Wrapper for VB.net
@VictorN:
Sorry if you could not read my code., I don't know how to put my code around the code snippets.
Originally Posted by VictorN
Please, edit your post to add the Code tags around the code snippets. Otherwise your code is absolutely unreadable!
-
August 29th, 2014, 03:47 AM
#6
-
August 29th, 2014, 06:56 AM
#7
Re: C++ Wrapper for VB.net
Thanks, VictorN for reminding me.., I tried to make it colorful but this is i've got..,
Originally Posted by VictorN
-
August 29th, 2014, 07:48 AM
#8
Re: C++ Wrapper for VB.net
Originally Posted by kpax1684
Thanks, VictorN for reminding me.., I tried to make it colorful but this is i've got..,
it's OK now. To be readable code has to be formatted with proper tabs7indentations and whitespaces. Colorisation is not so important!
Victor Nijegorodov
-
August 29th, 2014, 11:30 AM
#9
Re: C++ Wrapper for VB.net
Check out the pinvoke.net site.
-
September 2nd, 2014, 02:33 AM
#10
Re: C++ Wrapper for VB.net
I have checked the pinvoke site but I could not get a better explanation there..,
-
September 2nd, 2014, 11:53 AM
#11
Re: C++ Wrapper for VB.net
Originally Posted by kpax1684
I have checked the pinvoke site but I could not get a better explanation there..,
How you use the pinvoke.net site is you find a signature that is correct for your function prototype. There are many examples of Win32 prototypes so you should be able to find one similar to what you need.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|