MASM 64位 - 无法使CreateFileW工作。 CreateFileA工作正常

时间:2017-02-12 18:58:18

标签: assembly 64-bit masm createfile

CreateFileW返回-1,GetLastError返回2(系统找不到指定的文件。)

运行最新的VS社区2017 使用Windows 10和最新更新。

也尝试了这些注册设置:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Policies]
"LongPathsEnabled"=dword:00000001

代码:

;-------------------------------------------------------------------------------------------
extern ExitProcess:proc
extern CreateFileA:proc
extern CreateFileW:proc
extern ReadFile:proc
extern GetLastError:proc
extern CloseHandle:proc
;----------------------------------------------------------------------------------------------
GENERIC_READ            equ 080000000h
FILE_ATTRIBUTE_NORMAL   equ 080h
OPEN_EXISTING           equ 3
OPEN_ALWAYS             equ 4
;-------------------------------------------------------------------------------------------
.data
align 1
    gFileName       db "D:\C# Projects\TestAsm\Simple.txt", 0       ;Simple.txt contains Hello
    ;gFileName      db "\\?\D:\C# Projects\TestAsm\Simple.txt", 0   ;Tried this too.
    gFileHeapPtr    db 10 Dup(0)
;-------------------------------------------------------------------------------------------
align 8
    gFileHandle dq 0
    gBytesRead  dq 0
;-------------------------------------------------------------------------------------------
.code
;-------------------------------------------------------------------------------------------
main proc
    mov rbp, rsp

    mov rcx, offset gFileName
    mov rdx, GENERIC_READ
    xor r8, r8
    xor r9, r9

    push 0
    push FILE_ATTRIBUTE_NORMAL
    push OPEN_EXISTING

    sub rsp, 32
    call CreateFileA    ; CreateFileA works fine.
    ;call CreateFileW   ; Returns -1
    ;call GetLastError  ; Returns 2 > The system cannot find the file specified.
    mov rsp, rbp

    mov gFileHandle, rax

    mov rcx, gFileHandle
    mov rdx, offset gFileHeapPtr
    mov r8, 5

    lea rax, gBytesRead
    mov r9, rax
    push 0

    sub rsp, 32
    call ReadFile
    mov rsp, rbp

    mov rcx, gFileHandle
    sub rsp, 32
    call CloseHandle
    mov rsp, rbp

    call ExitProcess
main endp
;-------------------------------------------------------------------------------------------
End
;-------------------------------------------------------------------------------------------

0 个答案:

没有答案