Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted
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?
Printer Monitor for .NET? - see Merrion Computing Ltd for details
  • *Experts*
Posted

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.

  • *Experts*
Posted

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

Printer Monitor for .NET? - see Merrion Computing Ltd for details
  • *Gurus*
Posted
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? ;)
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...