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

  • SEARCH
  • Home
  • 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 190975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:18:06+00:00 2026-05-11T16:18:06+00:00

The Windows API DuplicateHandle() http://msdn.microsoft.com/en-us/library/ms724251(VS.85).aspx Requires the Object handle to be duplicated and a

  • 0

The Windows API DuplicateHandle()
http://msdn.microsoft.com/en-us/library/ms724251(VS.85).aspx
Requires the Object handle to be duplicated and a handle to both the original process AND the other process that you want to use the duplicated handle in.

I am assuming that if I have two UNRELATED processes, I could call DuplicateHandle() in either one so long as I had the required handles available?

My Question is about using a Pipe to communicate between the two processes to achieve this with an Event.

In the first process I CreateEvent(). Now I want to use WaitForSingleObject() in the second process.

If I try to duplicate the handle in the first process, I will need to first send the second process handle to the first process via the pipe, duplicate the handle and then send the handle over to the second process?

Alternativly, I could begin by sending the first process handle and the Event handle to the second process and just duplicate it there.

Is there a reason I should choose one over the other?

To add a wrinkle, the Event handle is actually inherited from the parent process that actually called the first process (which is a CGI application). If that Event handle was created with HANDLE_DO_NOT_DUPLICATE (something like that) then can I in fact use DuplicateHandle() to duplicate it for the second process?

Response:

Well I could create a new NAMED event in the first process and find it in the second process as suggested, but I am trying to DUPLICATE the event that was created in the parent of the first process and foreward it to the second process. This event is not a named event so I need to use DuplicateHandle().

I am using a pipe for the IPC. I am realizing that DuplicateHandle() will have to be called in the first process because the event handle is out of context when sent to the second process.

        hProcPseudo  = GetCurrentProcess() 

    //Then call either:
        lpRealHandle = OpenProcess( PROCESS_DUP_HANDLE, 0, hProcPseudo ) 
//This fails with GetLastError= 87 - The parameter is incorrect ???
// same thing with PROCESS_ALL_ACCESS ??


    //OR
        lRet = DuplicateHandle( hProcPseudo, hProcPseudo, hProcPseudo, lpRealHandle, DUPLICATE_SAME_ACCESS, 0, 0 )

    //then I can Duplicate my Event Handle in the first thread with:
        lRet = DuplicateHandle( hLocalProcess, hEvent, lpRealHandle, hDupEvent, DUPLICATE_SAME_ACCESS, 0, 0)

The second process converts its handle with DuplicateHandle() detailed above converting

hProcPseudo= 4294967295

to

hProcess= 152

Then I pass this process handle to the first process via the named pipe.
In the first process (where the event handle is valid) I call Duplicate handle:

DuplicateHandle( hFirstProcess, hEvent, hSecondProc, hDupEvent, DUPLICATE_SAME_ACCESS, 0, 0)

Unfortunatly I get the error:

DuplicateHandle hPipeFCGI GetLastError= 6 – The handle is invalid.

Further testing (substituting hFirstProcess) reveals it is hSecondProc that is invalid!??

Big Mystery.

  • 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-11T16:18:06+00:00Added an answer on May 11, 2026 at 4:18 pm

    Use a named pipe or mailslots for IPC, this should work reliably for your purpose. If you need to wait, use named wait handles.

    Otherwise, I’d choose to do DuplicateHandle in the second process in order to set the handle ownership correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the relationship between the Windows API and the C run time library?
I'm writing a class library that provides convenient object-oriented frontends to the C API
Exist any Windows api function to retrieve the WNDPROC for a Windows Handle? Thanks
Windows API ::FindWindow function fails when called from Service application. GetLastError() also returns 0
Using the Windows API, how can I get a list of domains on my
Are there Windows API functions that allows reading what the current password policy is?
Is there in Windows API or in MFC any analog to atoh() function? atoh()
Can some one specify the windows API, one need to use in order to
I am trying to use native windows API with Qt using mingw toolset. There
Is there a O(1) way in windows API to concatenate 2 files? O(1) with

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.