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.
The unmanaged C++ code:
Code:int log_connect(char* node, UINT dte, HANDLE* ptr_log) { HANDLE hLog = NULL; int rc = 0; rc = EmEvt_logOpen( node, dte, EMEVT_LOG_MODE_READ, &hLog ); ptr_log = &hLog; return rc; } int log_read(HANDLE* ptr_log, EMEVT_LOG* ptr_evt) { int rc = 0; rc = EmEvt_logRead( *ptr_log, 0, *ptr_evt ); return rc; }
My managed vb .net code (console app):
Code:<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 FunctionCode:'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)




Reply With Quote
