*Experts* Merrion Posted November 3, 2002 *Experts* Posted November 3, 2002 How can I get similar functionality to Err.LastDllError (from VB5/6) in VB.Net? I presume GetLastError api call is still suspect because of API functions that may trample on the error code being called internally by the programming language? Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
*Experts* Volte Posted November 3, 2002 *Experts* Posted November 3, 2002 The Err object still exists in VB.NET, along with LastDllError, but I'm not sure of the programming ethics that go along with it, since it's in the Microsoft.VisualBasic namespace, which as I understand is the compatability class. It should make a fine placeholder until you find a better way, however. Quote
*Gurus* Derek Stone Posted November 3, 2002 *Gurus* Posted November 3, 2002 System.Runtime.InteropServices.Marshal.GetLastWin32Error Quote Posting Guidelines
*Gurus* divil Posted November 3, 2002 *Gurus* Posted November 3, 2002 ...it's in the Microsoft.VisualBasic namespace, which as I understand is the compatability class... Only if you believe CL's lies! Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Gurus* Derek Stone Posted November 3, 2002 *Gurus* Posted November 3, 2002 Microsoft can call it whatever they want. That's partly what it's there for (it obviously also serves as the runtime). Quote Posting Guidelines
*Experts* Merrion Posted November 4, 2002 Author *Experts* Posted November 4, 2002 *Resolved* Err.LastDllError System.Runtime.InteropServices.Marshal.GetLastWin32Error Just what i was looking for - thanks... Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
*Experts* Merrion Posted November 4, 2002 Author *Experts* Posted November 4, 2002 It appears that you need to set the "SetLastError" attribute to make use of this e.g.: <System.Runtime.InteropServices.DLLImport("winspool.drv",EntryPoint:="GetJob",SetLastError:=True, _ CallingConvention:=CallingConvention.StdCall>_ Private Function GetJob(ByVal mhPrinter As Int32, _ ByVal dwJobId As Int32, _ ByVal Level As Print_Job_Command_Levels, _ ByVal lpJob As Int32, _ ByVal cbBuf As Int32, _ ByRef lpSizeNeeded As Int32) As Boolean End Function Incidentally - I'm not sure about "ByVal lpJob As Int32,". How should I pass a pointer to a byte buffer in? Thanks in advance, Duncan Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
*Gurus* Derek Stone Posted November 4, 2002 *Gurus* Posted November 4, 2002 Make a call to Marshal.AllocHGlobal which will return an IntPtr to a memory location. Call Marshal.Copy to transfer the managed byte array to unmanaged memory. Then call .ToInt32 on the IntPtr to convert the pointer to an integer that GetJob will recognize. Finally unallocate the memory using Marshal.FreeHGlobal. Catch all that? ;) Quote Posting Guidelines
*Experts* Merrion Posted November 4, 2002 Author *Experts* Posted November 4, 2002 Excellent - muchos gracias.. Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
Recommended Posts