Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

calling formatMessage() from VB5

Posted on 1998-06-21
6
Medium Priority
?
475 Views
Last Modified: 2008-02-01
Hi There !

I using wininet.dll to connect to ftp server, and i want to handle errors, I found that i have to use kernel32.dll formatMessage() (info from MSDN appendix c: handling errors).

That problem is I get "application error" or "mismach type" when I call this func, I belive it's becasue the the last parameter :va_list *args , and in the declaration (from API viewer) it's defined as long.

My questions are :
1. if parameter defined as va_list *Args in the dll - how to I declare it in Vb?
2. how do i send C++'s NULL ? - vbNullString doesn't work

thanks
0
Comment
Question by:avior
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

by:avior
ID: 1463888
Edited text of question
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1463889
avior,

  1. You declare the parameter with type va_list as "Long", since what the API required in this parameter is a pointer.
  2. To pass Null to Windows API, pass vbNullString to paramter declared as string or any, and pass 0 to parameter declared as Long or Integer.

Try following code and you could get the error message to related error no which return by GetLastError.

---' The code is in a BAS module
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
 
Public Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Public Const FORMAT_MESSAGE_ARGUMENT_ARRAY = &H2000
Public Const FORMAT_MESSAGE_FROM_HMODULE = &H800
Public Const FORMAT_MESSAGE_FROM_STRING = &H400
Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Public Const FORMAT_MESSAGE_IGNORE_INSERTS = &H200
Public Const FORMAT_MESSAGE_MAX_WIDTH_MASK = &HFF
Public Const LANG_USER_DEFAULT = &H400&
 

Function GetLastErrorStr(dwErrCode As Long) As String

  ' Let VB alloc the buffer. If FORMAT_MESSAGE_ALLOCATE_BUFFER
  ' was used, the lpBuffer param (sMsgBuf) would have to be a
  ' long pointer
  ' to the buffer & would then have to be freed when we're done.
  ' 256 chars is the maximun length for a resource string (+ 1     ' for the null char)
  Static sMsgBuf As String * 257, dwLen As Long

  dwLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM _
                        Or FORMAT_MESSAGE_IGNORE_INSERTS _
                        Or FORMAT_MESSAGE_MAX_WIDTH_MASK, _
                        ByVal 0&, _
                        dwErrCode, LANG_USER_DEFAULT, _
                        ByVal sMsgBuf, 256&, 0&)

  If dwLen Then
      GetLastErrorStr = Trim$(Left$(sMsgBuf, dwLen))
  Else
     GetLastErrorStr = "Unknown error."
  End If

End Function
--------

Regards.


0
 

Author Comment

by:avior
ID: 1463890
hi again !

first, thanks for the good answers, but as I said before when i call the function I get error message "MAILMAN caused an invalid page fault in module KERNEL32.DLL at 0137:bff7be3f.",
The call & the declaration are listed below , hope you can solve my problem.



' declarations

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
Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Declare Function GetLastError Lib "kernel32" () As Long

Public Const FORMAT_MESSAGE_FROM_HMODULE = &H800


Private Sub showError(dError As Long, funcName$)    
    Dim Buffer As String * 257
    Dim hWininetdll As Long, size As Integer
   
   
    ' get error description from wininet.dll
    hWininetdll = GetModuleHandle("wininet.dll")
    size = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE, hWininetdll, dError, 0&, ByVal Buffer, 256&, 0&)
    msgbox "error in func : " & funcName & ",desciription is :" & Trim$(Left$(Buffer, size))
end Sub

thanks, Avior
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:yowkee
ID: 1463891
avior,

  For page fault issue, pass hWininetdll byval. Eg.
size = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE, Byval hWininetdll, dError, 0&, ByVal Buffer, 256&, 0&)

  However, I do a simple test but didn't not get the error message from wininet.dll. I am not sure since I simply pass a error number to it. I am wondering is there anyway to find out a dll got message table or not.

  Regards.
0
 

Author Comment

by:avior
ID: 1463892
yowkee !

Thanks very much it did solve the problem, I realy have to get more expirence with calling dlls.

I dont have option to grade your answer, (and it's A for sure) since you added a comment ,please answer this so i can grade it.


Thanks , Avior  
0
 
LVL 4

Accepted Solution

by:
yowkee earned 400 total points
ID: 1463893
avior,

  You're welcome.
  Answer as my comment.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question