forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Kernel FormatMessage and GetLastError

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Help for VDS 5 & Up
View previous topic :: View next topic  
Author Message
hotwire
Newbie


Joined: 30 Jan 2005
Posts: 6

PostPosted: Sun Jan 30, 2005 1:25 pm    Post subject: Kernel FormatMessage and GetLastError Reply with quote

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
View user's profile Send private message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sun Jan 30, 2005 3:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sun Jan 30, 2005 5:54 pm    Post subject: Reply with quote

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 Smile

_________________
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
View user's profile Send private message Send e-mail
hotwire
Newbie


Joined: 30 Jan 2005
Posts: 6

PostPosted: Sun Jan 30, 2005 9:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
hotwire
Newbie


Joined: 30 Jan 2005
Posts: 6

PostPosted: Mon Jan 31, 2005 9:23 am    Post subject: Reply with quote

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
View user's profile Send private message
geicsge
Newbie


Joined: 27 Feb 2009
Posts: 19

PostPosted: Sat Mar 14, 2009 1:31 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Help for VDS 5 & Up All times are GMT
Page 1 of 1

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group