还是ReadFile函数的问题,请大牛帮帮忙。。。。
请大牛们帮我看看为什么我的程序会死在ReadFile。纠结死了,快哭了都。。。。。
function IsWindowsNT: BOOL;
var
osv : OSVERSIONINFO;
begin
osv.dwOSVersionInfoSize := SizeOf(osv);
GetVersionEx(osv);
if osv.dwPlatformId = VER_PLATFORM_WIN32_NT then
begin
Result := True;
end
else
begin
Result := False;
end;
end;
procedure TfrmBMain.ExecuteBack(const CommandLine : string);
var
sa : TSecurityAttributes;
sd : SECURITY_DESCRIPTOR;
lpsa : PSecurityAttributes;
hReadPipe : THandle;
hWritePipe : THandle;
si : TStartupInfo;
pi : TProcessInformation;
dest : array [0..100] of Char;
BytesRead : DWORD;
strString : string;
begin
lpsa := nil;
try
if (IsWindowsNT) then
begin
InitializeSecurityDescriptor(@sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(@sd,True,nil,False);
sa.nLength := SizeOf(SECURITY_ATTRIBUTES);
sa.bInheritHandle := True;
sa.lpSecurityDescriptor := @sd;
lpsa := @sa;
end;
Assert(CreatePipe(hReadPipe,hWritePipe,lpsa,2500000));
GetStartupInfo(si);
si.cb := SizeOf(TStartupInfo);
si.dwFlags := STARTF_USESHOWWINDOW + STARTF_USESTDHANDLES;
si.wShowWindow := SW_HIDE;
si.hStdOutput := hWritePipe;
si.hStdError := hWritePipe;
CreateProcess(
nil,
PChar(CommandLine),
nil, nil, True,
0, nil, nil,
si, pi
);
CloseHandle(pi.hThread);
WaitForSingleObject(pi.hProcess,0);
while True do
begin
if not PeekNamedPipe(hReadPipe,@dest,SizeOf(dest),nil,nil,nil) then Break;
if ReadFile(hReadPipe, dest, SizeOf(dest), BytesRead, nil) = True then
begin
strString := Copy(string(dest),1,BytesRead);
ShowMessage(strString);
if Length(strString) < SizeOf(dest) then Break;
end;
Sleep(200);
Application.ProcessMessages;
end;
CloseHandle(hWritePipe);
CloseHandle(hReadPipe);
Closehandle(pi.hProcess);
except
;
end;
end;
...全文
相关推荐
readfile函数详解
对串口通信readfile()函数的详细解释,参数的用法等等,
node.js中的fs.readFile方法使用说明
fs.readFile的实现源码在Node.js的内部是用C++编写的,具体是Node.js的lib模块,具体函数是readFile。其底层原理包括了对文件描述符的打开、读取、然后关闭文件描述符。
c#USB通信readfile
在给定的“c# USB通信readfile”项目中,开发者利用了readfile和writefile这两个关键API函数来完成C#程序与USB设备的数据交换。下面我们将深入探讨这些知识点。
Hook Api,hook ReadFile,hook WriteFile,hook LoadLibrary
通过对ReadFile、WriteFile和LoadLibrary等函数的Hook,我们可以实现文件操作的监控、动态库的控制以及其他高级功能。
Windows API一日一练(54)WriteFile和ReadFile函数.pdf
无论是保存用户数据、记录日志还是处理网络传输,WriteFile和ReadFile函数都是不可或缺的工具。


Windows SDK/API
