Using VB .NET 4.0 , I'm trying to run through some c++ unmanaged code..
The issue is that one function returns a HANDLE, and another needs the same HANDLE ref. I can tell the initial function is running successfully, but afterwards, the IntPtr is set to 0 (blank).
Naturally, it's driving me crazy, since this is the first time I've really had to work with P/Invoke. Unfortunately, I'm not sure what the HANDLE points too, since it's being returned from a file in an old compiled lib
Can * anyone * help with this? I've included the code below.
<DllImport("em_utilities.dll", CharSet:=CharSet.Auto)> _
Public Function log_connect(<MarshalAs(UnmanagedType.LPStr)> ByVal node As String, <MarshalAs(UnmanagedType.U4)> ByVal dte As UInteger, ByRef ptr_log As IntPtr) As Integer
End Function
<DllImport("em_utilities.dll", CharSet:=CharSet.Auto)> _
Private Shared Function log_read(ByRef ptr_log As IntPtr) As Integer
End Function
Code:
'Get today's date in requested format
Dim dte As UInteger = 10000 * DateTime.Today.Year + 100 * DateTime.Today.Month.ToString() + DateTime.Today.Day
Dim log As IntPtr
log_connect("server", dte, log)
If log = IntPtr.Zero Then
System.Console.WriteLine("IntPtr blank")
End If
log_read(log)
Re: return and reuse HANDLE from unmanaged c++ code
Some issues with your code :
Originally Posted by dwuser22
Code:
int log_connect(char* node, UINT dte, HANDLE* ptr_log){
int, may be equivalent to the short data type, so use short ineatd of Integer in VB
Originally Posted by dwuser22
Code:
Dim log As IntPtr '-- > Here you are declaring the IntPtr
log_connect("server", dte, log) '-->Here you are using it, it still being ZERO
If log = IntPtr.Zero Then '--> It is obviously still Zero
Last edited by HanneSThEGreaT; May 25th, 2011 at 09:17 AM.
Bookmarks