News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

fopen error falsely reported

Started by JohnnyReb, June 22, 2006, 11:52:24 AM

Previous topic - Next topic

JohnnyReb

Hi Y'all,

If I uncomment the PrintHex in the code below, I get a MessageBox "This function is only valid in Win32 mode" only on the first iteration.  The subsequent iterations get no MessageBox  I realize that the Error exists before this routine is called (probably somewhere in my setup logic), but my problem is the accuracy of the fopen error check.  It seems as if the result of the fopen request is not set before I test for it.

openf   proc
        .IF hFile != 0
            fclose  hFile       ; * Close any previously opened file *
        .ENDIF
        mov     hFile, fopen("testFile.xyz")    ; * Open new file
; PrintHex hFile
        invoke GetLastError         ; * Check for file open error *
        .IF eax != 0
            invoke MessageBox, hWnd, LastError$(), ADDR WindName, MB_OK
        .ENDIF
        fclose  hFile           ; for testing
        mov     hFile,0         ; clear for next iteration
        return 0
openf   endp

Thanks for considering my problem

hutch--

John,

Use the same technique with the macro as you would for "CreateFile()" as the macro is only a wrapper around the API call with all of the right flags set.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

JohnnyReb

hutch-
Thanks, I modified to:
      .IF eax == INVALID_HANDLE_VALUE
per the winapi and it now works correctly

Faiseur

fopen macro is good, but in the case if you open a file in "readonly" attribute, fopen return error (invalid_handle_value). That because fopen use "GENERIC_READ or GENERIC_WRITE" flags, and return error with GENERIC_WRITE flag. That is not to be forgotten.
French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/