Author Topic: FindFirstFile error  (Read 7525 times)

p3tr0va

  • Guest
FindFirstFile error
« on: October 10, 2012, 09:58:01 AM »
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)
Code: [Select]
.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)
Code: [Select]
#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

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: FindFirstFile error
« Reply #1 on: October 10, 2012, 10:10:50 AM »
You must check the return value of FindFirstFile:

Code: [Select]
.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

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: FindFirstFile error
« Reply #2 on: October 10, 2012, 10:56:16 AM »
Hi p3tr0va,

welcome to the forum.

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: FindFirstFile error
« Reply #3 on: October 10, 2012, 04:32:40 PM »
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

  • Guest
Re: FindFirstFile error
« Reply #4 on: October 11, 2012, 01:54:10 AM »
That works  :t
Thanks a lot!