Results 1 to 2 of 2

Thread: VB Snippet - Get last API error description

  1. #1

    Thread Starter
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616

    VB Snippet - Get last API error description

    When an API call is executed in VB and it has an error it usually sets the Err.LastDllError property to a number. You can decode this number to a meaningful description of the error as follows:

    VB Code:
    1. '\ API Error decoding
    2. Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
    3.  
    4. Public Function LastSystemError() As String
    5.  
    6. Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
    7. Dim sError As String * 500 '\\ Preinitilise a string buffer to put any error message into
    8. Dim lErrNum As Long
    9. Dim lErrMsg As Long
    10.  
    11. lErrNum = Err.LastDllError
    12.  
    13. lErrMsg = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, lErrNum, 0, sError, Len(sError), 0)
    14.  
    15. LastSystemError = Trim(sError)
    16.  
    17. End Function
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  2. #2
    New Member
    Join Date
    Aug 2001
    Location
    Sri Lanka
    Posts
    7
    thanx for the code!!!
    It says that, The printer name is invalid

    But when I used Windows 2000 Control Panel to add the printer manually, I select the name "EP" as the printer on the network.
    The name "EP" is the name of the printer I gave when installing and sharing.

    Here I'm putting for shareName and printerName, the same "EP"
    What can be the cause to get the above error?
    Am I to put "\EP" or "\\P2\EP" or any such?
    [Actually I checked with "\EP" and "\\P2\EP" but unsuccessful.

    Please help me!!
    I'm in the edge of the answer, but couldn't find.
    Regards
    Srinika

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width