下边是我写的一点代码,编译能过,但是执行程序的时候程序就卡死了,求大家帮忙!谢谢!
int USB_ADBcommand( char *sPath, char *sCommand, char *sInfo )
{
char sBuf[10240];
const int PIPE_BUFFER_SIZE = 10240;
HANDLE hReadPipe;
HANDLE hWritePipe;
STARTUPINFO adbProcStartup;
SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES),NULL, TRUE };
BOOL bResult = CreatePipe(&hReadPipe, &hWritePipe ,&sa, PIPE_BUFFER_SIZE);
if( bResult == 0 ) return 0;
PROCESS_INFORMATION adbProcInfo;
memset(&adbProcInfo, 0, sizeof(PROCESS_INFORMATION));
memset(&adbProcStartup, 0, sizeof(STARTUPINFO));
adbProcStartup.cb = sizeof(STARTUPINFO);
adbProcStartup.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
adbProcStartup.hStdOutput = hWritePipe;
adbProcStartup.hStdInput = hReadPipe;
adbProcStartup.wShowWindow = SW_HIDE;
if (strlen(sPath) > 0) sprintf(sBuf, "%s//%s", sPath, sCommand);
else sprintf(sBuf, sCommand);
if(!CreateProcess(NULL,sBuf,NULL,NULL,TRUE,NULL,NULL,NULL,&adbProcStartup, &adbProcInfo))
{
AfxMessageBox("进程错误()");
return -1;
}
char szFileBuf[PIPE_BUFFER_SIZE] ={0};
DWORD dwByteRead = 0;
// WriteFile(hWritePipe,szFileBuf ,strlen(szFileBuf), &dwByteRead, NULL);
// sprintf(sInfo, szFileBuf);
ReadFile(hReadPipe, szFileBuf, PIPE_BUFFER_SIZE, &dwByteRead, NULL);
sprintf(sInfo, szFileBuf);
CloseHandle(hWritePipe);
CloseHandle(hReadPipe);
return 0;
}
////////////////////////////////////////////////////////////////////////////
void CPCToolsDlg::OnBUTTONReadadder()
{
// TODO: Add your control notification handler code here
char sPath[64], sCmd[64], sInfo[10240];
sprintf(sPath, "C://Windows//system32");
sprintf(sCmd, "adb shell getbledevice");
// sprintf(sCmd, "adb shell");
int ret = USB_ADBcommand(sPath, sCmd, sInfo);
AfxMessageBox("");
GetDlgItem(IDC_EDIT_MessageBox)->SetWindowText(sInfo);