Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing pointers through windows messages?

Status
Not open for further replies.

BeanDog

Programmer
Jul 15, 2000
60
0
0
US
I am trying to ascertain whether a process running in a separate .exe, not just a separate thread, has completed (multithreading is not an option in this case). In the calling module, the following code executes:

volatile bool* IsDone = new bool;
*IsDone = false;
PostMessage(IndexWin, WM_INDEXER_PURGE_INDEX, (int)(IsDone), 0);
while(!(*IsDone))
{
Sleep(250);
Application->ProcessMessages();
}

So, we make a volatile bool (so it can be changed asynchronously), set it equal to false, and post a message to the other module using the pointer to the bool as the WPARAM. We then process messages until the other module
sets the bool equal to true.

In the other module, the following code is run:
volatile bool* IsDone = (bool*)Msg.WParam;
*IsDone = true;

I get an access violation from the second module when it tries to change the bool's value (writing to whatever address). Why? Is there a way to pass a pointer this way?



~BenDilts( void );




~BenDilts( void );
benbeandogdilts@cs.com
 
Yes. You can send a handle to an allocated memory. This memory shoyld be allocated with sequrity options(there should exist some security attributes structure) as non share exclusive as usualy. Try to se how to work with that structure. John Fill
1c.bmp


ivfmd@mail.md
 
Have a look in the 'Win32 Programmers reference' help file (came with builder) for the function call CreateSemaphore. If you are creating the new process from within the initial process (CreateProcess), the semaphore seems to encapsulate the functionality you are looking for with the bool stuff.

hth
scalp
 
don't forget about using files, memory mapped files, dlls, COM objects. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top