View previous topic :: View next topic |
Author |
Message |
hotwire Newbie
Joined: 30 Jan 2005 Posts: 6
|
Posted: Sun Jan 30, 2005 1:25 pm Post subject: Kernel FormatMessage and GetLastError |
|
|
I'm trying to convert windows error codes into their text using FormatMessageA. It this specific case, %e is being populated with 12007 (an internet lookup error), but FormatMessage is doing nothing special and I can't figure it out. Any help would be greatly appreciated.
Code: |
%e = @lib(KERNEL32,GetLastError,int:)
%m = @fill(256,,Z)
%c = @lib(KERNEL32,FormatMessageA,int:,$1000,0,int:%e,0,@ADDR("%m"),255,0)
warn %m
|
|
|
Back to top |
|
|
Skit3000 Admin Team
Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Sun Jan 30, 2005 3:28 pm Post subject: |
|
|
Maybe this works?
Code: | %e = @lib(KERNEL32,GetLastError,int:)
%m = @fill(256,,Z)
%c = @lib(KERNEL32,FormatMessageA,int:,int:$1000,int:0,int:%e,int:0,int:@ADDR("%m"),int:255,int:0)
warn @val(%m) |
_________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Jan 30, 2005 5:54 pm Post subject: |
|
|
If ya can't get this working, the free VDSug.dll has
a "GetLastError" function that returns the last Windows
error code as text.
Example: %%errmsg = @ug(GETLASTERROR)
Link is in my sig.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
hotwire Newbie
Joined: 30 Jan 2005 Posts: 6
|
Posted: Sun Jan 30, 2005 9:21 pm Post subject: |
|
|
Apparently my original code worked, but not with WININET error codes. After trying (and failing) with the InternetGetLastResponseInfo Function, I found a page on the msdev site which told how to get an handle for the dll error codes.... Here's what worked for me (obviously return code checking will be implemented):
Code: |
%%http_send = @lib(WININET,HttpSendRequestA,int:,%%http_request,nil:,0,nil:,0)
%e = @lib(KERNEL32,GetLastError,int:)
%f = @lib(KERNEL32,GetModuleHandleA,int:,str:wininet.dll)
%p = @fill(256,,Z)
%r = @lib(KERNEL32,FormatMessageA,int:,int:$800,%f,int:%e,int:0,@ADDR("%p"),int:255,int:0)
|
|
|
Back to top |
|
|
hotwire Newbie
Joined: 30 Jan 2005 Posts: 6
|
Posted: Mon Jan 31, 2005 9:23 am Post subject: |
|
|
This works a little better:
Code: |
:KERROR_WARN
LOADLIB KERNEL32
%e = @lib(KERNEL32,GetLastError,int:)
%f = 0
%p = @fill(256,,Z)
if @equal(@GREATER(%e,11999),@GREATER(12175,%e))
%f = @lib(KERNEL32,GetModuleHandleA,int:,str:wininet.dll)
end
%r = @lib(KERNEL32,FormatMessageA,int:,int:$800,%f,int:%e,int:0,@ADDR("%p"),int:255,int:0)
warn (%e) %p
FREELIB KERNEL32
exit
|
|
|
Back to top |
|
|
geicsge Newbie
Joined: 27 Feb 2009 Posts: 19
|
Posted: Sat Mar 14, 2009 1:31 am Post subject: |
|
|
Code: |
loadlib kernel32.dll
#DEFINE FUNCTION,GETLASTERROR
rem Get "The handle is invalid" error
%%currProcess =@LIB(kernel32,CloseHandle,%%currProcess)
%%tmp1 =@getlasterror(kernel32)
freelib kernel32.dll
stop
:GetLastError
# The GetLastError will return the last-error code value
# Parameters:
# dllname
#
# Syntax: %A = @GetLastError(<dllname>)
%%tmp1 =@lib(KERNEL32,GetLastError,INT:)
# Test for the first parameter. If NULL use the KERNEL32.DLL
If %1
%%tmp2 =@lib(KERNEL32,GetModuleHandleA,INT:,STR:%1.dll)
Else
%%tmp2 =@lib(KERNEL32,GetModuleHandleA,INT:,STR:kernel32.dll)
End
%x =@fill(256,,Z)
%%tmp3 =@lib(KERNEL32,FormatMessageA,INT:,INT:$0800,%%tmp2,INT:%%tmp1,INT:0,@ADDR("%x"),INT:255,INT:0)
warn API call error: %%tmp1 "(0x"@hex(%%tmp1)")"@cr()@adjust(%x)
exit
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|