?
Solved

calling formatMessage() from VB5

Posted on 1998-06-21
6
Medium Priority
?
469 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

764 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