|
Hi, I'm invoking ShellExecuteEx to launch another exe from my console application - the problem is, the call returns before the executing process is completed. Is there any way to get around this?
<br />
::ZeroMemory(&shellInfo, sizeof(shellInfo));<br />
<br />
shellInfo.cbSize = sizeof(shellInfo);<br />
shellInfo.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;<br />
shellInfo.lpFile = csCommand;<br />
shellInfo.lpParameters = csArgument;<br />
shellInfo.nShow = SW_HIDE;<br />
shellInfo.hMonitor = <br />
<br />
if (ShellExecuteEx(&shellInfo))<br />
{<br />
if (shellInfo.hProcess)<br />
{<br />
hProcess = shellInfo.hProcess;<br />
<br />
bSuccess = TRUE;<br />
}<br />
else<br />
{<br />
bSuccess = FALSE;<br />
}<br />
}<br />
else<br />
{<br />
bSuccess = FALSE;<br />
}
Thanks.
Norman Fung
|
|
|
|
|
Try searching for:
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
This should wait until it finishes.
Roy
|
|
|
|
|
if (shellInfo.hProcess)
{
hProcess = shellInfo.hProcess;
::WaitForSingleObject(hProcess, INFINITE);
*EDIT* Sorry baloneyman! I missed it by a minute
|
|
|
|
|
check the _cwait() function in msdn ... it includes an example
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
Solution here
<br />
BOOL bSuccess = TRUE;<br />
<br />
STARTUPINFO si = { sizeof(si) };<br />
PROCESS_INFORMATION pi;<br />
<br />
CString csCommand;<br />
CString csArgument;<br />
<br />
csCommand = strIsqlPath;<br />
<br />
csArgument = csCommand;<br />
csArgument += L" -U ";<br />
csArgument += strDBUsername;<br />
<br />
if(!strDBPassword.IsEmpty()) {<br />
csArgument += L" -P ";<br />
csArgument += strDBPassword;<br />
}<br />
<br />
csArgument += L" -S ";<br />
csArgument += strSourceServer;<br />
<br />
csArgument += L" -s, -w2500";<br />
<br />
csArgument += L" -i \"";<br />
csArgument += strSQLCmdPath;<br />
csArgument += L"\"";<br />
<br />
csArgument += L" -o \"";<br />
csArgument += strTradeExtractFilePath;<br />
csArgument += L"\"";<br />
<br />
try {<br />
<br />
if(<br />
CreateProcess(<br />
NULL,<br />
csArgument.GetBuffer(csArgument.GetLength()),<br />
NULL,<br />
NULL,<br />
NULL,<br />
NULL,<br />
NULL,<br />
NULL,<br />
&si,<br />
&pi<br />
)<br />
) {<br />
WaitForSingleObject(pi.hProcess, INFINITE);<br />
<br />
CloseHandle(pi.hProcess);<br />
CloseHandle(pi.hThread);<br />
}<br />
<br />
<br />
} catch(CException ex) {<br />
bSuccess = FALSE;<br />
ex.GetErrorMessage(errMsg, 0, NULL);<br />
}<br />
<br />
return bSuccess;<br />
-- modified at 20:36 Wednesday 27th December, 2006
Norman Fung
|
|
|
|
|
Hello everyone,
I want to write a program that gets input from the microphone. The volume of the input from the microphone will be used in a program. Based on the volume of the input, I want to increase the size of another variable.
Can anyone help with me this? where do I start from?
Thanks a million in advance.
Commickey
|
|
|
|
|
Commickey wrote: where do I start from?
Have you already decided to go with the Windows waveform audio system (waveIn, waveOut)?
If not, I would recommend examining the pros and cons of the different audio options:
For MCI and waveform audio there's
Windows Multimedia[^]
For DirectX (DirectSound) there's
DirectX SDK[^]
|
|
|
|
|
Thanks alot... I will consider ur suggestions...
Greetings,
Commickey
|
|
|
|
|
Is MCI_DGV_RECORD_PARMS helpfuls ?
|
|
|
|
|
I have an application with a main processing loop ( while(true){} ). When the application is running normally it eats up about 2% of the CPU. Whenever focus is taken away from the application window however, the CPU usage jumps to about 50%. This also happens when I comment out all of my code in the loop except the windows message queue processing and my app jumps from 60fps to about 2000fps.
My question is, how do I 'pause' processing when focus is taken away, but still have the abilty to get window messages so I know when focus is given back?
Thanks in advance,
Dustin
|
|
|
|
|
When your application receives the WM_KILLFOCUS message then set the thread priority to BelowNormal or Lowest or make the application thread sleep.
Hope it helps
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
That doesn't seem to work.
Am I doing this correctly? I have never created/manipulated threads before.
case WM_ACTIVATE:
{
if (LOWORD(wParam) == WA_ACTIVE)
{
HANDLE thread = GetCurrentThread();
SetThreadPriority(thread, THREAD_PRIORITY_NORMAL);
}
else
{
HANDLE thread = GetCurrentThread();
SetThreadPriority(thread, THREAD_PRIORITY_LOWEST);
}
}
break;
I also tried doing it on the WM_KILLFOCUS event but with the same results.
Thanks,
Dustin
|
|
|
|
|
Something i forgot when you posted was that you wanted to pause the processing not lower it.
try this if it does not work try send me an demo so i can test.
static bool g_bRunning = true;
case WM_ACTIVATE:
{
if (LOWORD(wParam) == WA_ACTIVE)
{
g_bRunning = true;
}
else
{
g_bRunning = false;
}
}
break;
while (!g_bRunning){};
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
Since my message peek is in the main loop, if I do that it will no longer look for messages and will not tell me when focus has been restored.
|
|
|
|
|
Well you could put a copy of the messagepeek functions to the while (!m_bRunning) {<here>}; then there should be no problems
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
Dustin Henry wrote: I comment out all of my code in the loop except the windows message queue processing and my app jumps from 60fps to about 2000fps.
What do you mean by "fps"? Typically a Windows message loop uses virtually no CPU until a
message is received. What's going on in your message loop?
Mark
|
|
|
|
|
fps = Frames per second. It is a Direct3D application.
Typically a Windows message loop uses virtually no CPU until a
message is received
I thought the same thing, but if I comment out all of my processing except for the message peek and dispatch, the app still eats the CPU when focus is lost.
Here is my entire WindowProc:
LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
return(0);
}
break;
case WM_LBUTTONDOWN:
{
POINT ptMouse = {(int)LOWORD(lParam),(int)HIWORD(lParam)};
g_pInterface->UpdateMouse(ptMouse, true);
}
break;
case WM_LBUTTONUP:
{
POINT ptMouse = {(int)LOWORD(lParam),(int)HIWORD(lParam)};
g_pInterface->UpdateMouse(ptMouse, false);
}
break;
case WM_MOUSEMOVE:
{
POINT ptMouse = {(int)LOWORD(lParam),(int)HIWORD(lParam)};
g_pInterface->UpdateMouse(ptMouse);
CString stMove;
stMove.Format("(%d,%d)",(int)LOWORD(lParam),(int)HIWORD(lParam));
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
}
break;
case WM_GRAPHNOTIFY:
{
g_pInterface->GetDirectShow()->OnGraphEvent();
}
break;
default:break;
}
return (DefWindowProc(hWnd, msg, wParam, lParam));
}
And my main loop: (the message part)
while(TRUE)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
Dustin
|
|
|
|
|
Try GetMessage instead of PeekMessage
You shouldn't have to sleep or mess with thread priority for user interface thread
Mark
|
|
|
|
|
Mark Salsbery wrote: What do you mean by "fps"?
Well i am guessing he is writing a game/game engine. Applications also lose focus when they are minimized. That is why he probaly needs the application to stop processing.
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
Sorry his reply was not there when i posted mine
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
Well I think I fixed it. I basically used CaveFox's idea of a running boolean but in the main loop placed:
if (!g_bRunning)
Sleep(1000);
I believe this was happening because I allow the program to basically sit and spin in an infinite loop. Even if I commented out everything in the while(), the same thing happened. I guess the program just needed something to do.
Any idea why this is?
Thanks for your help guys.
Dustin
|
|
|
|
|
No SLEEP()!!!
while(GetMessage(&msg,NULL,0,0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
|
|
|
|
|
This should stop all processing (except the messages).
case WM_ACTIVATE:
{
if (LOWORD(wParam) == WA_ACTIVE)
{
g_bRunning = true;
}
else
{
g_bRunning = false;
}
}
break;
static bool m_bRunning = true;
while(TRUE)
{
do
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
} while(!m_bRunning)
}
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|
|
Really, I BEG you guys...pleeeease leave the poor UI thread alone
What did it ever do to you???
|
|
|
|
|
Yea it was a little overkill (by me ) ... im sleep deprived and are not thinking strait. Should have solved it with the first post
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?
|
|
|
|