做了2个小程序,没有读成功;文件打开了;

		.386
		.model flat, stdcall
		option casemap :none
 
include		windows.inc
include		user32.inc
includelib	user32.lib
include		kernel32.inc
includelib	kernel32.lib
include		Comdlg32.inc
includelib	Comdlg32.lib
 
ICO_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	proc
		local	@stOF:OPENFILENAME
		local   @iFileLength, @dwBytesRead, @hFile
		local	@szBuffer[512]:byte
 
		invoke	RtlZeroMemory,addr @stOF,sizeof @stOF
		mov	@stOF.lStructSize,sizeof @stOF
		push	hWinMain
		pop	@stOF.hwndOwner
		mov	@stOF.lpstrFilter,offset szFilter
		mov	@stOF.lpstrFile,offset szFileName
		mov	@stOF.nMaxFile,MAX_PATH
		mov	@stOF.Flags,OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST
		invoke	GetOpenFileName,addr @stOF
		.if	eax
			invoke	MessageBox,hWinMain,addr szFileName,addr szCaption,MB_OK
			;invoke CreateFile, @stOF.lpstrFile, GENERIC_READ, FILE_SHARE_READ,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
			invoke	CreateFile,addr szFileName,GENERIC_READ,FILE_SHARE_READ,0,\
			OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
                        .if	eax ==	INVALID_HANDLE_VALUE
				invoke	MessageBox,hWinMain,addr szErrOpenFile,NULL,MB_OK or MB_ICONEXCLAMATION
				ret
			.endif
			invoke	MessageBox,hWinMain,addr szOpenFile,NULL,MB_OK
			mov	@hFile,eax

			;invoke GetFileSize, @hFile, NULL
			;mov @iFileLength, eax
			invoke ReadFile, @hFile, addr @szBuffer, sizeof @szBuffer, addr @dwBytesRead, 0
			invoke	MessageBox,hWinMain,addr @szBuffer,NULL,MB_OK
			invoke SetDlgItemText,hWinMain,IDC_INFO,addr @szBuffer
		.endif
		ret
 
_OpenFile	endp
 
 
_ProcDlgMain	proc	uses ebx edi esi hWnd,wMsg,wParam,lParam
		mov	eax,wMsg
		.if	eax ==	WM_CLOSE
			invoke	EndDialog,hWnd,NULL
		.elseif	eax ==	WM_INITDIALOG
		.elseif	eax ==	WM_COMMAND
			mov	eax,wParam
			.if	ax ==	IDM_EXIT
				invoke	EndDialog,hWnd,NULL
			.elseif	ax ==	IDM_OPEN
				invoke	_OpenFile
			.endif
		.else
			mov	eax,FALSE
			ret
		.endif
		mov	eax,TRUE
		ret
_ProcDlgMain	endp
 
start:
		invoke	GetModuleHandle,NULL
		mov	hInstance,eax
		invoke	DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
		invoke	ExitProcess,NULL
		end	start
		.386
		.model flat,stdcall
		option casemap:none
 
include		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
 
		.code
 
start:
                invoke	CreateFile,addr filename,GENERIC_READ,FILE_SHARE_READ,0,\
			OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
                        .if	eax ==	INVALID_HANDLE_VALUE
				invoke	MessageBox,NULL,addr szErrOpenFile,NULL,MB_OK or 

MB_ICONEXCLAMATION
				ret
			.endif
			invoke	MessageBox,NULL,addr szOpenFile,NULL,MB_OK
			mov	hFile,eax


			invoke ReadFile, hFile, addr szBuffer, 1024, addr dwBytesRead, 0
			invoke	MessageBox,NULL,addr szBuffer,NULL,MB_OK

                
		invoke	ExitProcess,NULL
		end	start

win32 汇编读文件-LMLPHP 

有时间继续;

02-22 09:12