Reputation: 49
The following task is on the agenda: "Use the GetOpenFileName function to select a file. Check if the file is less than 3 days old, execute it. Otherwise, display a dialog box asking about deleting the file. If the user is useful, wipe it." (Attention. If the task says to use a structure, then it must be placed in dynamically allocated memory)
After successful execution of the GetOpenFileName function, I want to open the selected file. I tried two options:
I refused OpenFile as it is obsolete.
I figured out a little with CreateFile, but for some reason the eax
register is filled with FFFFFFFF
, and the debugger writes: "Syntax error in the file name, folder name or volume label," although the idea should not be(((
And if I just leave [edi].lpstrFile
, then eax 0000057C
File.inc
include WINDOWS.inc
include user32.inc
include kernel32.inc
include comdlg32.inc
includelib user32.lib
includelib kernel32.lib
includelib comdlg32.lib
.data
Time_title db ' Lab_3',0
buf db 255 dup(0)
File.asm
.386
.model flat,STDCALL
option casemap :none ;case sensitive
include Third.inc
include RADbg.inc
Mem_Alloc PROC Buf_Size:DWORD
add Buf_Size,4
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,Buf_Size
push eax
invoke GlobalLock,eax
pop [eax]
add eax,4
ret
Mem_Alloc endp
Mem_Free PROC DATA:DWORD
mov eax,DATA
sub eax,4
mov eax,[eax]
push eax
push eax
call GlobalUnlock
call GlobalFree
ret
Mem_Free endp
.code
Begin:
call main
invoke ExitProcess,NULL
main proc
LOCAL hFile:DWORD
LOCAL ftCreate, ftLocale: FILETIME;
LOCAL stUTC, stLocal: SYSTEMTIME;
invoke Mem_Alloc, sizeof OPENFILENAME
mov edi, eax
assume edi: ptr OPENFILENAME
xor eax, eax
mov [edi].lStructSize, sizeof OPENFILENAME
mov [edi].lpstrFile, offset buf
mov [edi].nMaxFile, 255
invoke GetOpenFileName, edi
invoke CreateFile, addr [edi].lpstrFile, GENERIC_READ,\ ;немного разобрался
FILE_SHARE_READ, NULL, OPEN_EXISTING,\
FILE_ATTRIBUTE_NORMAL, NULL
mov hFile,eax
invoke GetFileTime, hFile, addr ftCreate, NULL, NULL
invoke FileTimeToLocalFileTime, addr ftCreate, addr ftLocale
invoke FileTimeToSystemTime, addr ftCreate, addr stUTC
jne l1
jmp l2
assume edi: dword
invoke Mem_Free, hFile
l1:
l2:
ret
main endp
end Begin
Upvotes: 1
Views: 150