avoiding multiple instances
-
great... thanks. As a side note, I have to say THANKS to everyone at CodeProject, and everyone that uses CodeProject. I started using VC++ in September on my first real project at work. Coming from Visual Basic, I was a little intimidated making the transition, but CP has really made it less painless, and even enjoyable experience. Thanks for help everyone. Marcus Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope -- Daniel Burnham
Marcus, I think there's a flaw in your piece of code. Instead of
CreateMutex( NULL, TRUE, "MVD Load Utility" )
you should use
CreateMutex( NULL, FALSE, "MVD Load Utility" );
Good luck. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
Marcus, I think there's a flaw in your piece of code. Instead of
CreateMutex( NULL, TRUE, "MVD Load Utility" )
you should use
CreateMutex( NULL, FALSE, "MVD Load Utility" );
Good luck. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
thanks. I read the MSDN on CreateMutex, but I can't make heads or tails of what the difference is. BTW - in your previous example, how did you get the code to appear in beige? Marcus Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope -- Daniel Burnham
-
thanks. I read the MSDN on CreateMutex, but I can't make heads or tails of what the difference is. BTW - in your previous example, how did you get the code to appear in beige? Marcus Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope -- Daniel Burnham
thanks. I read the MSDN on CreateMutex, but I can't make heads or tails of what the difference is. The difference is that when
bInitialOwner
is set toTRUE
, the system gives ownership to the first process that creates the mutex, as if it has subsequently calledWaitForSingleObject
on the mutex handle. As ownership is not needed for your purposes (you are only resorting to mutexes as a convenient way to share global identifier across proceses),bInitialOwner
is best left asFALSE
(moreover, you'd have to expliciy callRelaseMutex
later, which is not the same as closing the handle). Pff, what a messy explanation, hope you've understand something of it :) To get the beige background enclose your code between <pre> and </pre> tags. Regards Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
thanks. I read the MSDN on CreateMutex, but I can't make heads or tails of what the difference is. BTW - in your previous example, how did you get the code to appear in beige? Marcus Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope -- Daniel Burnham
Use the <pre> tags!
this is between two 'pre' tags
Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
-
thanks. I read the MSDN on CreateMutex, but I can't make heads or tails of what the difference is. The difference is that when
bInitialOwner
is set toTRUE
, the system gives ownership to the first process that creates the mutex, as if it has subsequently calledWaitForSingleObject
on the mutex handle. As ownership is not needed for your purposes (you are only resorting to mutexes as a convenient way to share global identifier across proceses),bInitialOwner
is best left asFALSE
(moreover, you'd have to expliciy callRelaseMutex
later, which is not the same as closing the handle). Pff, what a messy explanation, hope you've understand something of it :) To get the beige background enclose your code between <pre> and </pre> tags. Regards Joaquín M López Muñoz Telefónica, Investigación y DesarrolloIf his program exits, he need not call ReleaseMutex as the mutex object itself gets destroyed [or am I highly erroneous here?] Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
-
If his program exits, he need not call ReleaseMutex as the mutex object itself gets destroyed [or am I highly erroneous here?] Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
"highly erroneous"? that sounds painful! Sorry to dissapoint you all with my lack of a witty or poignant signature.
-
thanks. I read the MSDN on CreateMutex, but I can't make heads or tails of what the difference is. The difference is that when
bInitialOwner
is set toTRUE
, the system gives ownership to the first process that creates the mutex, as if it has subsequently calledWaitForSingleObject
on the mutex handle. As ownership is not needed for your purposes (you are only resorting to mutexes as a convenient way to share global identifier across proceses),bInitialOwner
is best left asFALSE
(moreover, you'd have to expliciy callRelaseMutex
later, which is not the same as closing the handle). Pff, what a messy explanation, hope you've understand something of it :) To get the beige background enclose your code between <pre> and </pre> tags. Regards Joaquín M López Muñoz Telefónica, Investigación y DesarrolloJoaquín... You have shed some light in this dark world of mine. X| It made as much sense as it could for a beginner C++ programmer.
where can I find the docs on how to use other tags (or are there any other)
thanks again. Marcus Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope -- Daniel Burnham
-
If his program exits, he need not call ReleaseMutex as the mutex object itself gets destroyed [or am I highly erroneous here?] Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
Hi Nish, Well, the thing is a little tricky, because the documentation is not conclusive on this. I haven't found nowehere that closing a mutex handle implies also releasing it, so to the best of my knowledge not calling
ReleaseMutex
is undefined behavior (though it is perfectly possible that everything works nevertheless). All in all, as the guy didn't need ownership at all, I think it is better to remain on the safe side and simply settingbInitialOwner
toFALSE
Regards, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
Joaquín... You have shed some light in this dark world of mine. X| It made as much sense as it could for a beginner C++ programmer.
where can I find the docs on how to use other tags (or are there any other)
thanks again. Marcus Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope -- Daniel Burnham
Apart from <pre> you can use <code> to get an effect like
this
. If you're including code of yours that may have the character '<', replace those with the escape sequence < Also, you can use regular HTML tags as well. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
"highly erroneous"? that sounds painful! Sorry to dissapoint you all with my lack of a witty or poignant signature.
LOL Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
-
Hi Nish, Well, the thing is a little tricky, because the documentation is not conclusive on this. I haven't found nowehere that closing a mutex handle implies also releasing it, so to the best of my knowledge not calling
ReleaseMutex
is undefined behavior (though it is perfectly possible that everything works nevertheless). All in all, as the guy didn't need ownership at all, I think it is better to remain on the safe side and simply settingbInitialOwner
toFALSE
Regards, Joaquín M López Muñoz Telefónica, Investigación y DesarrolloThanks for your thoughts and time Joaquín! I guess you were correct in your advice to him :-) Regards Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
-
Hi Nish, Well, the thing is a little tricky, because the documentation is not conclusive on this. I haven't found nowehere that closing a mutex handle implies also releasing it, so to the best of my knowledge not calling
ReleaseMutex
is undefined behavior (though it is perfectly possible that everything works nevertheless). All in all, as the guy didn't need ownership at all, I think it is better to remain on the safe side and simply settingbInitialOwner
toFALSE
Regards, Joaquín M López Muñoz Telefónica, Investigación y DesarrolloMutexes are automatically released. Here is a quote from Helen Custler's Inside Windows NT book which talks about this history of mutants and mutexes in NT. "The name /mutant/ has a colorful [sic] history. Early in Windows NT's development, Dave Cutler created a kernel mutex object that implemented low-level mutual exclusion. Later he discovered that OS/2 required a version of the mutual-exclusion semaphore with additional semantics, which Dave considered "brain-damaged" and which was incompatible with the original object. (Specifically, a thread could abandon the object and leave it inaccessible.) So he created an OS/2 version of the mutex and gave it the name /mutant/. Later Dave modified the mutant object to remove the OS/2 semantics, allowing the Win32 subsystem to use the object. The Win32 API calls the modified object /mutex/, but the native services retain the name /mutant/." Tim Smith Descartes Systems Sciences, Inc.
-
Mutexes are automatically released. Here is a quote from Helen Custler's Inside Windows NT book which talks about this history of mutants and mutexes in NT. "The name /mutant/ has a colorful [sic] history. Early in Windows NT's development, Dave Cutler created a kernel mutex object that implemented low-level mutual exclusion. Later he discovered that OS/2 required a version of the mutual-exclusion semaphore with additional semantics, which Dave considered "brain-damaged" and which was incompatible with the original object. (Specifically, a thread could abandon the object and leave it inaccessible.) So he created an OS/2 version of the mutex and gave it the name /mutant/. Later Dave modified the mutant object to remove the OS/2 semantics, allowing the Win32 subsystem to use the object. The Win32 API calls the modified object /mutex/, but the native services retain the name /mutant/." Tim Smith Descartes Systems Sciences, Inc.
Beautiful piece of wisdom :) Anyway, I wouldn't rely on only this paragraph to merrily abandon mutexes unreleased, withouth stronger confirmation from the documentation. Regards, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
Joaquín... You have shed some light in this dark world of mine. X| It made as much sense as it could for a beginner C++ programmer.
where can I find the docs on how to use other tags (or are there any other)
thanks again. Marcus Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope -- Daniel Burnham
Marcus2001 wrote: where can I find the docs on how to use other tags In the VC forum FAQ :) --Mike-- My really out-of-date homepage "Hey, you wanna go to the Espresso Pump and get sugared up on mochas?" -- Willow Rosenberg Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.