News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

FindFirstFile error

Started by p3tr0va, October 10, 2012, 09:58:01 AM

Previous topic - Next topic

p3tr0va

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.

qWord

You must check the return value of FindFirstFile:

.if eax == INVALID_HANDLE_VALUE
    call WriteWindowsMsg ; GetLastError is valid
.else
    ; success ; GetLastError has no meaning
.endif
MREAL macros - when you need floating point arithmetic while assembling!

Gunther

Hi p3tr0va,

welcome to the forum.

Gunther
You have to know the facts before you can distort them.

jj2007

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.

p3tr0va

That works  :t
Thanks a lot!