Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 762093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:54:58+00:00 2026-05-14T15:54:58+00:00

I have a thread function on Process B that contains a switch to perform

  • 0

I have a thread function on Process B that contains a switch to perform certain operations based on the results of an event sent from Process A, these are stored as two elements in an array.

I set the first element to the event which signals when Process A has data to send and I have the second element set to the event which indicates when Process A has closed.

I have began to implement the functionality for the switch statement but I’m not getting the results as I expect.

Consider the following:

//Thread function
        DWORD WINAPI ThreadFunc(LPVOID passedHandle)
        {    
            for(i = 0; i < 2; i++)
            {
                ghEvents[i] = OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("Global\\ProducerEvents"));
                if(ghEvents[i] == NULL)
                {
                    getlasterror = GetLastError();
                }
            }
            dwProducerEventResult = WaitForMultipleObjects(
                2,
                ghEvents,
                FALSE,
                INFINITE);

        switch (dwProducerEventResult) 
        {
        case WAIT_OBJECT_0 + 0: 
            {
                //Producer sent data
                //unpackedHandle = *((HWND*)passedHandle);

                MessageBox(NULL,L"Test",L"Test",MB_OK);
                break;
            }
        case WAIT_OBJECT_0 + 1:
            {
                //Producer closed
                ExitProcess(1);
                break;
            }
        default: 
            return;
        }

}

As you can see if the event in the first array is signalled Process B should display a simple message box, if the second array is signalled the application should close.

When I actually close Process A, Process B displays the message box instead.

If I leave the first case blank (Do nothing) both applications close as they should.

Furthermore Process B sends data an error is thrown (When I comment out the unpacking):

Error Image

Have I implemented my switch statement incorrectly? I though I handled the unpacking of the HWND correctly too, any suggestions?

Thanks for your time.

Edit:

The example I’m following: Here

Event creation in Process A:

for (i = 0; i < 2; i++) 
            { 
                ghEvents[i] = CreateEvent( 
                    NULL,   // default security attributes
                    TRUE,  // auto-reset event object
                    FALSE,  // initial state is nonsignaled
                    TEXT("Global\\ProducerEvents"));  // unnamed object

                if (ghEvents[i] == NULL) 
                { 
                    printf("CreateEvent error: %d\n", GetLastError() ); 
                    ExitProcess(0); 
                } 
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:54:59+00:00Added an answer on May 14, 2026 at 3:54 pm

    Why are you opening the same event twice?

    ghEvents[i] = OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("Global\\ProducerEvents"));
    

    Shouldn’t there be two different events?

    This is consistent with the behavior you are reporting

    When I actually close Process A,
    Process B displays the message box
    instead.

    Because when you close process A the same event is signalled that enters the switch as WAIT_OBJECT_0 + 0

    To sum up, create two different events – one for when process A is closing and the other to signal the message box to be shown.

    The code below will only work for i <= 0 <= 9 But the main point is that the cycle iteration must create an event with a different name.

    Process A:

    LPTSTR eventName[] = _T("Global\\ProducerEventi");
    for (i = 0; i < 2; i++) 
    { 
        eventName[20] = '0' - i; // this will change last i character with '0' or '1'
        ghEvents[i] = CreateEvent(NULL, TRUE, FALSE, eventName);
     ...
    

    Process B:

    LPTSTR eventName[] = _T("Global\\ProducerEventi");
    for(i = 0; i < 2; i++)
    {
        eventName[20] = '0' - i; // this will change last i character with '0' or '1'
        ghEvents[i] = OpenEvent(EVENT_ALL_ACCESS, FALSE, eventName);
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use seed data. Run rake db:setup to create the databases,… May 14, 2026 at 8:24 pm
  • Editorial Team
    Editorial Team added an answer I'd suggest using positions = ((n, n + hits_per_page -… May 14, 2026 at 8:24 pm
  • Editorial Team
    Editorial Team added an answer You may check out prawn too. Tutorial can be found… May 14, 2026 at 8:24 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.