Hi,
I am trying to create many instances from one application, but every instances should have different event. So every time I execute my application, one instance will create a new event.
I use the following lines:
string temp = "A";
while(OpenEvent(EVENT_ALL_ACCESS, FALSE, (LPCWSTR)temp.c_str()) != NULL)
{
char now = temp.at(temp.size()-1);
now ++;
temp.at(temp.size()-1) = (char)now;
}
myEvent = CreateEvent(NULL,TRUE,FALSE,(LPCWSTR)temp.c_str());
It maybe not so effective, but it works well (I execute the output exe multiple times and I get different event for every instance) until when I want to debug the code and I run my visual studio in the DEBUG mode, and then I run the executable and I get the same event as the one from VS. Is it because debug has different memory Can someone explain to me what is happening because it will be great if I can debug as well as running the other application.
Thank you

Debug has different memory?
zdrae
Troy Lundin
OpenEvent (and CreateEvent) enables you to create and open global event objects (shared among processes), so if you wish to have one for a connected set of release executables, and another one for the debug set, you should consider naming thereafter. E.g. "MyApplicationEvent" and "MyApplicationEventDebug".
Troy Lundin
If I understood correctly the first part what you are trying to do could be replaced with:
myEvent = CreateEvent(NULL,TRUE,FALSE, NULL); //unnamed event is better for your program
As for the second part - how do you know it is the same object
Allen Razdow
actually my application will create one event everytime its executed. before creating it, it iterates from A to Z to check wheter this eventName has been used(i.e. there is another instance of my application using it) and then choose the unused name. That's also the reason I give the event name.
However, what I experience now is that first I run my first instance from visual studio, then I run the second instance from the executable using command prompt, My second instance cannot detect the first event that is supposed to be created by the first instance from visual studio.
This is not the case if I run the first instance from command prompt also. If I run first and second instance from the command prompt, the later instance will detect the previous's event.
detect here means OpenEvent(....) will not return null
So my question will be, what can cause this situation Can anyone explain to me
chingling
And I think it will look nicer to pass a string rather than HANDLE ...
at least that's what i'm thinking :D
AlexBB
I don't understand what you are doing well enough to say anything specific to what you are doing, so I will explain some things that seem relevant.
Each application (process) executes in memory separate from all other processes. See my Processes and Address Spaces for my description of that. The Visual Studio debugger works for only one address space for each instance of the debugger. Does that explain what is happening
NetPochi
Note that the expression (LPCWSTR)temp.c_str() does not seem to be good since temp is not an Unicode string. It may work only accidentally. Because of some initialization differences of debug and release versions, the behaviour can be different.
You must either make temp Unicode using std::wstring class, or use OpenEventA and CreateEventA functions instead: