My progs allways have Errors "The specified module could not be found" and "The handle is invalid". This errors appears even when i'm useing tmplate win32 in radasm. For example:

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
;Togle Break Point here <-----"The specified module could not be found"

invoke LoadImage,hInst,addr backa,IMAGE_BITMAP,600,500,LR_LOADFROMFILE
mov hbackgr,eax
;And second one here <------"The handle is invalid"

btw this program works but maby something new will not work when i add to this prog.

Maby its windows which starts with this errors by default :tongue:
Posted on 2003-04-02 05:47:22 by AceEmbler
Show us your whole source code (if its nothing top secret ;) )
Posted on 2003-04-02 08:00:01 by bazik
It's a secret code so dont show it to anybody :eek:
Posted on 2003-04-02 08:34:29 by AceEmbler
Paranoid :grin:

Oh ya, remember to SetLastError to 0 and call the function then call GetLastError
Posted on 2003-04-02 08:47:58 by roticv

Paranoid :grin:

Oh ya, remember to SetLastError to 0 and call the function then call GetLastError


I'm useing PrintError <--- VKdebug so i dont use GetLastError
And the problem is why this errors appears in template window ???
Posted on 2003-04-02 09:01:04 by AceEmbler
I suppose PrintError works like this



PrintError macro
local pDesc
local info
if DBGWIN_DEBUG_ON eq 1
pushad
.data
pDesc dword 0
.code
invoke GetLastError
invoke FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, 0, eax, 0, addr pDesc, 0, 0
;FormatMessage returns length of err description in eax
if DBGWIN_EXT_INFO eq 1
info textequ @CatStr(< !(>, SFileName(), <!, >, %@Line, <!)>)
push eax
add eax, @SizeStr(%info)+1
invoke GlobalAlloc, GPTR, eax
push eax
invoke lstrcpy, eax, pDesc
pop eax
pop edx
push eax
add eax, edx
sub eax, 2
FillMem eax, %info
pop eax
invoke DebugPrint, eax
else
invoke DebugPrint, pDesc
endif
invoke LocalFree, pDesc
popad
endif
endm


They still make use of GetLastError :stupid:

But of course I would use my own macro


ErrorMessage macro
IFNDEF ErrorMessage_lpmsg
.data?
ErrorMessage_lpmsg dd ?
.code
ENDIF
call GetLastError
invoke FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, NULL, eax, LANG_NEUTRAL,\
ADDR ErrorMessage_lpmsg,0,NULL
invoke MessageBox, 0, ErrorMessage_lpmsg, 0, MB_OK
invoke LocalFree, ErrorMessage_lpmsg
endm
Posted on 2003-04-02 10:38:10 by roticv
But i dont wont to cover errors i wont to solve the problems.
And the qestion is. Why is this heapening, im making everything proper there:(
Posted on 2003-04-02 11:02:53 by AceEmbler
I can't find a single error in your prog. You have to remember that the printerror will print if it happens to find non-zero value in the return from a GetLastError command. A non-zero return from GetLastError does not necessarily mean that you have an error there are some functions that put a value into it when they succeed as well. You can only use the printerror command when you check to see if there actually was an error, i.e. some function returns INVALID_HANDLE_VALUE otherwise it's contents are unreliable. For example :

Invoke SetLastError,0 ; Reset the error before the call
Invoke CreateWindowEx,Blah blah blah
.IF eax == NULL ; Check to see if the returned value will be useful
printerror
.ENDIF
From MSDN
You should call the GetLastError function immediately when a function's return value indicates that such a call will return useful data. That is because some functions call SetLastError(0) when they succeed, wiping out the error code set by the most recently failed function.
This is demonstated by the fact that you are getting file errors when you aren't even using files
Posted on 2003-04-02 11:25:16 by donkey

I can't find a single error in your prog. You have to remember that the printerror will print if it happens to find non-zero value in the return from a GetLastError command. A non-zero return from GetLastError does not necessarily mean that you have an error there are some functions that put a value into it when they succeed as well. You can only use the printerror command when you check to see if there actually was an error, i.e. some function returns INVALID_HANDLE_VALUE otherwise it's contents are unreliable. For example :

Invoke SetLastError,0 ; Reset the error before the call
Invoke CreateWindowEx,Blah blah blah
.IF eax == NULL ; Check to see if the returned value will be useful
printerror
.ENDIFThis is demonstated by the fact that you are getting file errors when you aren't even using files


What a relief thx Donkey :alright:
Posted on 2003-04-02 12:27:54 by AceEmbler
BTW The file error you were getting was actually from the RegisterClassEx function that for some strange reason always generates an error # 2 even if it is successful "ERROR_FILE_NOT_FOUND".
Posted on 2003-04-02 12:34:42 by donkey
Hi, I'm getting the same problem, "RegisterClassEx" returns API error 2 ERROR_FILE_NOT_FOUND, even though it returns a non zero number. Presumably we just ignore it ?
Posted on 2004-07-26 02:42:44 by trueazian
Hi, I'm getting the same problem, "RegisterClassEx" returns API error 2 ERROR_FILE_NOT_FOUND, even though it returns a non zero number. Presumably we just ignore it ?
Posted on 2004-07-26 03:29:48 by trueazian
Yes. Be sure that you call SetError before calling RegisterClassEx to check whether the error really belong to RegisterClassEx.
Posted on 2004-07-26 06:45:44 by roticv
Hi thanks for the prompt reply, is it a good idea to call "SetError" before calling any function that returns an error code ?

cheers,

mark
Posted on 2004-07-26 07:48:24 by trueazian
Yes, to clear up any errors that may occur before the function.
Posted on 2004-07-26 07:53:19 by roticv
Cheers, I'll give it a try.

BTW is it possible that the 'file not found error' was left over from another thread ?, because i also get a dialogue box from my debugger saying exactly the same !
(Should have mentioned that I guess)

Thanks again

mark
Posted on 2004-07-26 08:23:56 by trueazian
RegisterClassEx returns an ATOM for the registered class.
There is an error if it returns 0.
Posted on 2004-07-26 16:16:11 by tenkey
OK, I can't find "SetError" in any include's, or any info on it, which beggers the question what is it and how do i use it ?

Thanks in advance


Mark
Posted on 2004-07-27 06:45:56 by trueazian
My mistake. It is called SetLastError.
Posted on 2004-07-27 08:19:47 by roticv