win32 汇编读文件

做了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

 

有时间继续;

  • 10
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值