|
-
February 16th, 2008, 09:06 AM
#1
While Writing Exe get hang...
Hi all...
Making a prog which call ping with specific argument... I'm creating pipe to read and write the data... I'm successfully reading the content content but when i try to write the data in my EDITBOX it get hang...
What could be the prob???
Also do i need to take some othere control to print my putput???
When i use "MessageBox(hwnd,Buffer,"a",MB_OK);"
It gives output without any trouble... But i don't need message box..
I want to redirect in EDITBOX or some other control..
Here is my code..
Any reply will be appreciated
thanks..
Code:
BOOL MyFunction(HWND hwnd)
{
STARTUPINFO si = {0};
SECURITY_ATTRIBUTES saAttr = {0};
HANDLE hReadPipe = NULL, hWritePipe = NULL;
PROCESS_INFORMATION pi = {0};
DWORD NumberOfBytesRead = 0;
TCHAR Buffer[500] = "";
si.cb = sizeof( si );
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
BOOL cp = CreatePipe( &hReadPipe, &hWritePipe, &saAttr, 0 );
if ( !cp)
{
MessageBox(NULL, "Failed to create pipe.", "Error", MB_OK);
return(FALSE);
}
si.dwFlags |= STARTF_USESTDHANDLES;
si.hStdOutput = hWritePipe;
cp = CreateProcess( NULL, (LPTSTR)(LPCTSTR)"ping 192.168.0.96", NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi );
if (!cp)
{
MessageBox(NULL, "Failed to create process.", "Error", MB_OK);
return(FALSE);
}
while(::ReadFile( hReadPipe, Buffer, sizeof(Buffer)/sizeof(Buffer[ 0 ])-1,&NumberOfBytesRead, NULL ) )
{
if (NumberOfBytesRead)
{
Buffer[ NumberOfBytesRead ] = TCHAR( 0 );
SetFocus(GetDlgItem(hwnd, IDC_EDIT1));
SetDlgItemText(hwnd, IDC_EDIT1, Buffer);
//MessageBox(hwnd,Buffer,"a",MB_OK);
}
else
{
break;
}
}
// Close write pipe
if(hWritePipe)
{
CloseHandle( hWritePipe );
}
if(hReadPipe)
{
CloseHandle( hReadPipe );
}
WaitForSingleObject( pi.hProcess, INFINITE );
cp = TRUE;
return(cp);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WindowInterfaceInstance = hInstance;
MSG msg;
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)WindowInterfaceProc);
int bRet;
while((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(FALSE);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|