Hi everyone!
I'm trying to write an app like the dir command, but when I use the FindFirstFile function
I get error:126 The specific module could not be found.
I wrote the code in c and is ok, no error.
Why? What's wrong? (the OS is windows xp sp3)
Here is in assembly (error)
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\irvine32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\irvine32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
.data
fName db "*.*",0
fData WIN32_FIND_DATA <>
.data?
hFile HANDLE ?
.code
start:
push offset fData
push offset fName
call FindFirstFile
mov hFile,eax
call WriteWindowsMsg ; Irvine's proc to see error
push 0
call ExitProcess
end start
Here is in C (ok)
#include <stdio.h>
#include <windows.h>
int main(int argc, char *argv[])
{
char path[]="*.*";
HANDLE hdl;
WIN32_FIND_DATA fd;
hdl=FindFirstFile(path,&fd);
printf("Error: %d\n",GetLastError());
return 0;
}
Thanks.
You must check the return value of FindFirstFile (http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx):
.if eax == INVALID_HANDLE_VALUE
call WriteWindowsMsg ; GetLastError is valid
.else
; success ; GetLastError has no meaning
.endif
Hi p3tr0va,
welcome to the forum.
Gunther
Hi p3tr0va,
Welcome to the forum. qWord is right, as usual, but to demonstrate the effect, you can add this:
invoke SetLastError, 0
push offset fData
push offset fName
call FindFirstFile
Windows' logic is "if eax signals a good value, why should I bother clearing the last error?". That's why you have to check - by the way, also in C.
P.S.: You can use Kip Irvine's lib and Masm32 in parallel, see here for an example (http://masm32.com/board/index.php?topic=767.msg6585#msg6585).
That works :t
Thanks a lot!