|
I am using Joseph M. Newcomer's WaitInfo
An Introduction to Processes: Asynchronous Process Notification[^]
to run multiple processes. I needed multiple WaitInfo because each time it will overwrite the hProcess info so I made WaitInfo into a vector
std::vector<WaitInfo> waiter
Next I have it
HANDLE hProcess = Launch(_T("notepad.exe"));
int idx = (int)waiter.size() + 1;
waiter.resize(idx);
waiter.at(idx-1).requestNotification(hProcess, this);
The code can launch 3 notepad without a problem.
However upon terminating either first two notepad it would crash. If I terminate the last one it would fine.
I traced it back to
::WaitForSingleObject(hProcess, INFINITE);
notifyee->PostMessage(UWM_PROCESS_TERMINATED, 0, (LPARAM)hProcess);
For the first two hProcess became 0xfeefee and the last process had the correct hProcess value.
I am unsure why the first two lost it's hProcess value. At the time of WaitForSingleObject their hProcess were correct. Since each WaitInfo has it's own vector so it shouldn't overwrite or clear the first two.
Well from the looks of it notifyee is gone as well.
modified on Thursday, May 13, 2010 5:58 PM
|
|
|
|
|
Orion Star wrote: waiter.resize(idx); // Increase vector size for the new process
waiter.at(idx-1).requestNotification(hProcess, this);
Is WaitInfo copy constructible and assignable. Perhaps when the vector is reallocating it's storage and copying the old contents to the new buffer a problem is occurring. Test this by calling reserve on the vector to set the final size before adding and elements:
std::vector<WaitInfo> waiter;
waiter.reserve(10);
Steve
|
|
|
|
|
Doesn't look like it
I tried
waiter.reserve(idx+1) and waiter.reserve(idx+10)
before I resize. Same problem
The thing is I checked waiter content, hProcess and notifyee, right after
waiter.at(idx-1).requestNotification(hProcess, this);
HANDLE check = waiter.at(idx-1).GetHandle()
and each time it's correct from my program side.
I just don't know why they are gone after the process ends
|
|
|
|
|
That's fundamentally unsafe…when you call requestNotification, the WaitInfo class passes its address to the thread it creates, and uses that address. When you resize a vector, it's likely to move its content when it has to reallocate storage, invalidating the pointer that was passed to the thread.
You're probably better off using a std::list, as it doesn't move items when it is altered. It's also just as easy to use (you could use the insertion code I show for vector as well…):
std::list<WaitInfo> waiter;
HANDLE hProcess = Launch(_T("notepad.exe"));
waiter.push_back(WaitInfo());
waiter.back().requestNotification(hProcess, this);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
I will give that a shot and see how that goes
I happy to report you are correct. I was able to close them without crashing and from my trace they have the correct value.
Thanks
|
|
|
|
|
How would I choose between writing into files in big-endian or little-endian format? Is there a way to tell fwrite() to do this?
|
|
|
|
|
fwrite or any other file operation will not do it for you.
You will have to do it yourself.
Windows is by default little-endian.
You can use the socket functions htonl and htons to toggle between big-endian and little-endian.
|
|
|
|
|
fwrite writes bytes. it doesn't know anything about endianness. so, if you're writing an int, you'll get the bytes from that int in the order they're stored in memory.
if that's not the order you want, you'll need to swap the bytes before calling fwrite.
|
|
|
|
|
hi guys
I have an app that has some dialogs opened, is kind of storage system.
When i update a price in a dialog i want the other ones to be notified of the change, is there a way to do this?
I know that using messages is an option but how to signal all dialogs.
Thanks
|
|
|
|
|
You could implement a simple Observer[^] mechanism.
Watched code never compiles.
|
|
|
|
|
Are the dialogs modal or modeless. Do they have a common parent?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
some are modal and some not but there could be at the same time 1 or more modeless with a modal
|
|
|
|
|
The application and all its dialogs can use RegisterWindowMessage[^] with the same string to get the same value.
Now use SendMessage[^] and specify the hWnd parameter as HWND_BROADCAST and the Msg parameter as the value returned by RegisterWindowMessage .
|
|
|
|
|
thanks, They should all have the same parent window?
|
|
|
|
|
Broadcast is only sent to top level windows and not child windows.
|
|
|
|
|
Hi ,
I am trying to get running application process ID So I am iterating every exe name and comapring using EnumProcessModules.
It is wroking fine on XP but on vista I am not getting name for all running process.For some process I am able to see the process name but not for all.
What might be the issue?
|
|
|
|
|
It could be a permission issue.
Try running application with administrator privileges. Right click -> Run as administrator.
|
|
|
|
|
I have a simple MFC app, where I use SetWindowPos(Left, right, Width, height) in my InitInstance(). What do I need to do to launch this app from the command line and specify the four parameters with the command line as well? I know it does have to do with
CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); , but not sure how to go about it.
Thanks
|
|
|
|
|
|
Thanks, will take a look.
|
|
|
|
|
Software2007 wrote: What do I need to do to launch this app from the command line and specify the four parameters with the command line as well?
If you are running your app from a command prompt, use:
myapp.exe <left> <right> <width> <height>
If you are running your app from within Windows, change the properties of the icon to include the <left> <right> <width> <height> values.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I am drawing on a dialog. Many rectangles are drawn. When I minimize the dialog the previous rectangles erase. How can I retain all rectangles?
|
|
|
|
|
How you draw the rectangles?
Where you draw the rectangles?
For example, have you implemented OnPaint method of the dialog to handle the drawing ?
Watched code never compiles.
|
|
|
|
|
the fitst replyer is very good.
|
|
|
|
|
I am drawing on a dialog and I am doing that in a thread.
|
|
|
|