Click here to Skip to main content
15,847,583 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 6:02
ForNow10-Nov-16 6:02 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
leon de boer10-Nov-16 9:25
leon de boer10-Nov-16 9:25 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 9:50
ForNow10-Nov-16 9:50 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
Randor 10-Nov-16 6:06
professional Randor 10-Nov-16 6:06 
AnswerRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
Albert Holguin10-Nov-16 8:32
professionalAlbert Holguin10-Nov-16 8:32 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 8:50
ForNow10-Nov-16 8:50 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
Albert Holguin10-Nov-16 8:58
professionalAlbert Holguin10-Nov-16 8:58 
GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
leon de boer10-Nov-16 9:38
leon de boer10-Nov-16 9:38 
You do realize you don't pass the handle around between threads right?

Read carefully
Two or more processes can call CreateMutex to create the same named mutex. The first process actually creates the mutex, and subsequent processes open a handle to the existing mutex. This enables multiple processes to get handles of the same mutex, while relieving the user of the responsibility of ensuring that the creating process is started first. When using this technique, you should set the bInitialOwner flag to FALSE; otherwise, it can be difficult to be certain which process has initial ownership.


If you go the other way and guarantee the inital thread opens it first you need to set the bInitialOwner flag and do a release. So your other choice.
The creating thread can use the bInitialOwner flag to request immediate ownership of the mutex. Otherwise, a thread must use one of the wait functions to request ownership. When the mutex's state is signaled, one waiting thread is granted ownership, the mutex's state changes to nonsignaled, and the wait function returns. Only one thread can own a mutex at any given time. The owning thread uses the ReleaseMutex function to release its ownership.


You seem to get getting confused between the two modes from what I am reading. You need to make a choice (a) or (b).

So I think you are getting this error because you are using the named technique without a name.
If lpName matches the name of an existing event, semaphore, waitable timer, job, or file-mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same namespace.

In vino veritas


modified 10-Nov-16 14:53pm.

GeneralRe: ERROR_INVALID_HANDLE returned From WaitForSingleObject after CreateMutex Pin
ForNow10-Nov-16 9:53
ForNow10-Nov-16 9:53 
QuestionDebug Assertion Failed error by WaitForMultipleObjectsEx in 64 bit application Pin
Member 123356959-Nov-16 21:27
Member 123356959-Nov-16 21:27 
AnswerRe: Debug Assertion Failed error by WaitForMultipleObjectsEx in 64 bit application Pin
Richard MacCutchan9-Nov-16 23:54
mveRichard MacCutchan9-Nov-16 23:54 
AnswerRe: Debug Assertion Failed error by WaitForMultipleObjectsEx in 64 bit application Pin
Randor 10-Nov-16 3:00
professional Randor 10-Nov-16 3:00 
GeneralRe: Debug Assertion Failed error by WaitForMultipleObjectsEx in 64 bit application Pin
Member 1233569510-Nov-16 23:44
Member 1233569510-Nov-16 23:44 
GeneralRe: Debug Assertion Failed error by WaitForMultipleObjectsEx in 64 bit application Pin
Member 1233569510-Nov-16 23:51
Member 1233569510-Nov-16 23:51 
AnswerRe: Debug Assertion Failed error by WaitForMultipleObjectsEx in 64 bit application Pin
Randor 11-Nov-16 5:06
professional Randor 11-Nov-16 5:06 
AnswerRe: Debug Assertion Failed error by WaitForMultipleObjectsEx in 64 bit application Pin
Albert Holguin10-Nov-16 8:36
professionalAlbert Holguin10-Nov-16 8:36 
QuestionHow to design pure C style APIs for a framework which include a core exe and plugin dlls Pin
bestbear9-Nov-16 20:59
bestbear9-Nov-16 20:59 
AnswerRe: How to design pure C style APIs for a framework which include a core exe and plugin dlls Pin
Richard MacCutchan9-Nov-16 23:52
mveRichard MacCutchan9-Nov-16 23:52 
AnswerRe: How to design pure C style APIs for a framework which include a core exe and plugin dlls Pin
leon de boer10-Nov-16 10:06
leon de boer10-Nov-16 10:06 
GeneralRe: How to design pure C style APIs for a framework which include a core exe and plugin dlls Pin
bestbear10-Nov-16 19:11
bestbear10-Nov-16 19:11 
QuestionC programming Determine Students grade Pin
Member 128422149-Nov-16 13:37
Member 128422149-Nov-16 13:37 
AnswerRe: C programming Determine Students grade Pin
leon de boer9-Nov-16 15:27
leon de boer9-Nov-16 15:27 
QuestionHow explicit , volatile and mutable keywords works INTERNALLY in C++ ? Pin
Amrit Agr6-Nov-16 23:06
Amrit Agr6-Nov-16 23:06 
AnswerRe: How explicit , volatile and mutable keywords works INTERNALLY in C++ ? Pin
Richard MacCutchan7-Nov-16 1:18
mveRichard MacCutchan7-Nov-16 1:18 
AnswerRe: How explicit , volatile and mutable keywords works INTERNALLY in C++ ? Pin
leon de boer7-Nov-16 9:15
leon de boer7-Nov-16 9:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.