|
|
|
|
#1 | |
|
Junior Member
Join Date: Apr 2006
Posts: 24
|
Help with ReleaseMutex
Hi, I was wondering if anyone could advise me on how to go about using this API call.
code: I have a macro, provided by the wiki pages: code: Upon reading the "Synchronization Object Security and Access Rights" page on MSDN, I noticed this: Quote:
I'm also not exactly sure how to get the Handle of the Mutex. I'm guessing it's not simply it's name right? The reason I want to release the Mutex, is that my installer creates two mutex's. One identical to the game I'm trying to patch (so they cannot run the game while trying to patch), and one of it's own, so the user can't run it twice. (reason there being two is that I can set a specific message depending on what the situation is.) Anyways. At the finish page, I have the option to lauch said game I'm patching. The game won't lauch if it loads faster than the installer can close itself (almost always). So I want to release the Mutex in my Finish Page preFunction. Thank you very much for your time in reading this. |
|
|
|
|
|
|
#2 |
|
Forum King
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
|
There is a plugin at wiki http://nsis.sourceforge.net/CreateMutex_plug-in that might be helpful.
Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Apr 2006
Posts: 24
|
Unfortunately that plug-in only deals with the creation of a mutex. Not releasing one.
Maybe I wasn't direct enough in my first post, I apologise. What I am after is a basic example of how to use the ReleaseMutex API call using the System plug-in. And also if I need to modify the existing Macro to allow for permissions to release it. Thank you for your assistance : ) |
|
|
|
|
|
#4 |
|
Forum King
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
|
You're welcome!
Just found this forum thread. http://forums.winamp.com/showthread....hreadid=131968 I hope that should be helpful. Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Apr 2006
Posts: 24
|
Ah, I also came across that thread during my search. While it seemed promising from the title, after the user found out how to create the Mutex, they didn't bother discussing anything further on how to release it. Hee hee~
I guess all the System/API guru's are on holiday at the moment? : ( Oh well, I might have to remove the 'run' tickbox at the end. Thanks again for your reply. |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Mar 2006
Location: Dallas
Posts: 462
|
The MSDN page for CreateMutex says the return value is the mutex handle. The macro you have is storing the handle (the return code) in _outvar, but then pops the System::Call return code from GetLastError into the same variable. I suggest changing the macro to put the handle into its own variable:
code: And use it something like this: code: Don |
|
|
|
|
|
#7 |
|
Member
Join Date: Jan 2006
Location: Canberra, Australia
Posts: 76
|
Don't forget to use CloseHandle on the mutex when you are done with it - Windows won't destroy it until all processes that have an open handle on the mutex close it.
While it is true that Windows will clean up when the process exits, relying on this is really a sign of poor code; you should always clean up your own resources explicitly. Duncan |
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Apr 2006
Posts: 24
|
Thank you all very much for your replies!
Here is what I have so far: Macro: code: Usage: code: Release: code: MessageBox is displaying "Return: error" Hmm, when I use... code: It returns 0, but still doesn't lat me lauch. Does the loop have something to do with it? |
|
|
|
|
|
#9 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
Your MutexCheck macro has syntax errors. i.$$0 is not a valid parameter definition for the System plug-in. You should pass i.r0 instead.
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Apr 2006
Posts: 24
|
Thanks kichik for your reply.
I was wondering if you could explain a little further about my error. Sorry to say, but I'm still pretty green on the System plug-in, API calls, and the using the internal NSIS stack itself. I'm not sure how you are getting i.$$0 Is that from "i .${_hMutex}" ? I've tried many other arrangements, and I'm still not able to get it working. I even stripped everything down to the very basics: PHP Code:
It is returning error. Is that because I'm using invalid parameter definition? Or is it because I need to change the default security settings of the Mutext itself? Thank you again for your time. |
|
|
|
|
|
#11 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
It was supposed to be just `i.$0`, I had a typo. System plug-in parameters are divided into three - type, input and output. When you use $0 for the output, the actual value of $0 will be copied into there and you'll eventually get something like `i.123`. This doesn't tell System where to put the value it gets, it tells it what value to put there. You must tell it in which register you want to put the value, and that can only be done with `r*`.
You also have another error there, where the type is wrong. It's a pointer to an integer, not an integer. Use an asterisk before the `i`. For more information, read the System manual, it has a few step by step guides and some examples. NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#12 |
|
Junior Member
Join Date: Apr 2006
Posts: 24
|
Thank you kichik.
I finally got it working : ) Here's a snippet if anyone else is having any issues with it: PHP Code:
So I had to put in a little counter of sorts, to let it find 0 once before skipping ahead to the abort. As you can see, I'm not the neatest, or most innovative scripter about, so don't expect anything special : P Thanks once again for everyone's help. |
|
|
|
|
|
#13 |
|
Major Dude
|
sorry, small question:
what do you need "ReleaseMutex" for? ![]() i never used it, because every mutex my installers create on startup seem to be released automatically with their shutdown again. hand by comm@nder21 ---------- WiKi pages:CreateInternetShortcut|Enhanced FindWindow|Parse CSV-Data|Open/Close CD-Drive|Installer without Icon|Vista application compatibility |
|
|
|
|
|
#14 | |
|
Senior Member
Join Date: Dec 2005
Location: Glow
Posts: 285
|
Quote:
|
|
|
|
|
|
|
#15 |
|
Major Dude
|
ah, read it!
sounds reasonable
hand by comm@nder21 ---------- WiKi pages:CreateInternetShortcut|Enhanced FindWindow|Parse CSV-Data|Open/Close CD-Drive|Installer without Icon|Vista application compatibility |
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|