做了2个小程序,没有读成功;文件打开了;
.386.model flat, stdcalloption casemap :noneinclude windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include Comdlg32.inc
includelib Comdlg32.libICO_MAIN equ 1000
DLG_MAIN equ 1000
IDM_MAIN equ 1000
IDM_OPEN equ 1101
IDM_EXIT equ 1104
IDC_INFO equ 101.data
;szBuffer db 1024 dup (?) .data?
hInstance dd ?
hWinMain dd ?szFileName db MAX_PATH dup (?).const
szCaption db '执行结果',0
szFilter db 'Text Files(*.txt)',0,'*.txt',0,'All Files(*.*)',0,'*.*',0,0
szDefExt db 'txt',0
szErrOpenFile db '无法打开源文件!',0
szOpenFile db '打开源文件成功!',0.code
; 显示“打开文件”对话框
_OpenFile proclocal @stOF:OPENFILENAMElocal @iFileLength, @dwBytesRead, @hFilelocal @szBuffer[512]:byteinvoke RtlZeroMemory,addr @stOF,sizeof @stOFmov @stOF.lStructSize,sizeof @stOFpush hWinMainpop @stOF.hwndOwnermov @stOF.lpstrFilter,offset szFiltermov @stOF.lpstrFile,offset szFileNamemov @stOF.nMaxFile,MAX_PATHmov @stOF.Flags,OFN_FILEMUSTEXIST or OFN_PATHMUSTEXISTinvoke GetOpenFileName,addr @stOF.if eaxinvoke MessageBox,hWinMain,addr szFileName,addr szCaption,MB_OK;invoke CreateFile, @stOF.lpstrFile, GENERIC_READ, FILE_SHARE_READ,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULLinvoke CreateFile,addr szFileName,GENERIC_READ,FILE_SHARE_READ,0,\OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0.if eax == INVALID_HANDLE_VALUEinvoke MessageBox,hWinMain,addr szErrOpenFile,NULL,MB_OK or MB_ICONEXCLAMATIONret.endifinvoke MessageBox,hWinMain,addr szOpenFile,NULL,MB_OKmov @hFile,eax;invoke GetFileSize, @hFile, NULL;mov @iFileLength, eaxinvoke ReadFile, @hFile, addr @szBuffer, sizeof @szBuffer, addr @dwBytesRead, 0invoke MessageBox,hWinMain,addr @szBuffer,NULL,MB_OKinvoke SetDlgItemText,hWinMain,IDC_INFO,addr @szBuffer.endifret_OpenFile endp_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParammov eax,wMsg.if eax == WM_CLOSEinvoke EndDialog,hWnd,NULL.elseif eax == WM_INITDIALOG.elseif eax == WM_COMMANDmov eax,wParam.if ax == IDM_EXITinvoke EndDialog,hWnd,NULL.elseif ax == IDM_OPENinvoke _OpenFile.endif.elsemov eax,FALSEret.endifmov eax,TRUEret
_ProcDlgMain endpstart:invoke GetModuleHandle,NULLmov hInstance,eaxinvoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULLinvoke ExitProcess,NULLend start
.386.model flat,stdcalloption casemap:noneinclude windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib.data
szBuffer db 1024 dup (?) .data?
hFile dd ?
dwBytesRead dd ?.const
filename db 'D:\文本类型资料\cmem.txt',0
szErrOpenFile db '无法打开源文件!',0
szOpenFile db '打开源文件成功!',0.codestart:invoke CreateFile,addr filename,GENERIC_READ,FILE_SHARE_READ,0,\OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0.if eax == INVALID_HANDLE_VALUEinvoke MessageBox,NULL,addr szErrOpenFile,NULL,MB_OK or MB_ICONEXCLAMATIONret.endifinvoke MessageBox,NULL,addr szOpenFile,NULL,MB_OKmov hFile,eaxinvoke ReadFile, hFile, addr szBuffer, 1024, addr dwBytesRead, 0invoke MessageBox,NULL,addr szBuffer,NULL,MB_OKinvoke ExitProcess,NULLend start
有时间继续;