文件创建成功,为什么还会有“不能打开源文件写!”的对话框出现 - C++ Builder / Windows SDK/API
.386
.model flat,stdcall
option casemap:none
includeE:\masm32\include\windows.inc
includeE:\masm32\include\user32.inc
includelibE:\masm32\lib\user32.lib
includeE:\masm32\include\kernel32.inc
includelibE:\masm32\lib\kernel32.lib
.data
lpfilenamedb'c:\windows\test.vbs',0
filestringdb'Set WshShell = Wscript.CreateObject("Wscript.Shell")',0dh,0ah,'WshShell.run "taskkill /im taskmgr.exe /f",0',0
ErrOpendb'不能打开源文件写!',0
ErrOpen1 db '成功!',0
lpfilename1 db 'cmd /c c:\windows\test.vbs',0
.code
_procfile proc
local @hfile,@dwbyte
invoke CreateFile,ADDR lpfilename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
.if eax==INVALID_HANDLE_VALUE
invoke MessageBox,NULL,addr ErrOpen,NULL,MB_OK
ret
.endif
mov @hfile,eax
xor eax,eax
invoke WriteFile,@hfile,addr filestring,sizeof filestring,addr @dwbyte,0
invoke FlushFileBuffers,@hfile
.if eax
invoke MessageBox,NULL,addr ErrOpen1,NULL,MB_OK
.endif
_procfile endp
start:
call _procfile
invoke WinExec,addr lpfilename1,SW_HIDE
invoke ExitProcess,NULL
end start
为什么????????????????
[解决办法]
此贴应该发到汇编版。既然错误是因为:
.if eax==INVALID_HANDLE_VALUE
invoke MessageBox,NULL,addr ErrOpen,NULL,MB_OK
证明你的文件创建失败。应该检查调用参数是否正确。