Jump to content


Photo

Oneinstance Mutex Dll - My First Asm Dll


  • Please log in to reply
5 replies to this topic

#1 Toon-Master

Toon-Master

    Half-Toon Hero!

  • New Member
  • 340 posts

Posted 20 January 2007 - 03:13 PM

Post from the past...

Name: MutexDLL (DLL name is ToonInstanceMutex.DLL)
Description: This DLL makes only one instance of a program. So you can only run one and when you try to run another, it is closed already (although the piece of code is still executed before close).
Download Link: http://host-a.net/to...er/MutexDLL.zip
Size: 5kb around (not being precise, just says it when looking at the icon)
--People's interest--
DLL made using programming language? ASM (High level syntax form)
Assembled using: MASM32 see DLL resource section (Source Code included in download).
Credit Required? Nope, don't need it.

Hello all, the first paragraph is my little story ignore it if you want;

This is my first ASM DLL for Game Maker (I don't count an example as first that is in my signature). I wanted to try making a ASM DLL for Game Maker and manage to get the basis on making DLLs with it. During the learning, I had no idea how to pass a double type value into the DLL. I tried the tutorial from VitalDragon but he only showed how to load it to the FPU stack. Of course I was stupid to realize you can pop values out of the stack to a variable of some sort to able to pass the right data type through. Even though I got it working, I used high level syntax of ASM like if statements or something easier to call functions.

This DLL will make a Game Run on one instance only. Meaning if you try to open another one of the programs that uses my DLL will be closed automatically. It uses game_end to end the game, so even if I call that the Piece of Code is still run unless I use exit;

It makes the program "One Instance" only by the use of Mutex. I seen this example program that does this so I might make use of it for use. The DLL only has two functions:
- ToonMutexStart(name,[dllpath]); This creates the mutex and sees if the mutex already exists or was already created. We do this by giving it a name (see example). Returns 1 for success (handle is stored in the DLL), -2 for already called it, -1 for already used in another instance.
- ToonMutexEnd(); This frees the DLL and the mutex using the reason parameter in the DLL to see if it has being freed from the process.

As mentioned an example and scripts are there for demonstration. This can be useful if you wanted only one instance of that programmed to be runned.

If you know better then me at this, maybe you can help me with some useful tips. I'll appreciate anything useful. Or maybe bugs?

NOTE: I saw the DLL OneInstance by Roach. It's not meant for competing, it's for a ASM example for people to learn if they wanted too.

The source is included for learning uses. Feel free to use it for your own DLL without my credit. The source is commented at my best. Please read, Readme.txt included in the package for a bit of info on the source. There is also another example in my sig which does add, return a string and MessageBox wrapper of, MessageBoxA function.

DWORD data type is considered a string and REAL8 is the double.

I hope there was some use or interest for learning.

- Toon-Master

EDIT: Idea from here, http://vcfaq.mvps.org/mfc/2.htm

EDIT2: If you can't get the DLL to work (I know this is a known issue by now), use http://www.toonidyzo...loads/mutex.zip This one is made in C++ and it is also open source. Thanks and sorry about this unexpected failure D:


Here is the new ASM DLL, I fixed the error. I passed the wrong stuff in CreateMutex on the ASM one so sometimes it's bound to be different.

C++ Version: http://www.toonidyzo...loads/mutex.zip
MASM Version: http://host-a.net/to...tance_Mutex.zip

Source code is easier to read too haha. I also avoided some high level syntax ASM :/

See scripts for the new function names, I got rid of "Toon". Again no credit is required.

Idea on Mutex One Instance here: http://vcfaq.mvps.org/mfc/2.htm

I don't know if this DLL will not error like the one on Roach's (apparently).

Enjoy,
- Toon-Master

Edited by Toon-Master, 24 May 2008 - 05:51 AM.

  • 0
D: I'm sorry if I'm unavailable for answering questions through messaging on GMC.
-------------------------------------------------------------------
I love Leanny Basil, Heart on Artivale. You inspired me for so many years.

#2 Daniel-Dane

Daniel-Dane

    GMC Member

  • New Member
  • 3581 posts

Posted 20 January 2007 - 06:39 PM

I see you finally busted the double problem :chikin.

This DLL is great, not long time ago I saw a topic where a member asked how to prevent the user to open two instances of a game. There were many good suggestions but this should be the safest one.

Good work :P!
  • 0

#3 Toon-Master

Toon-Master

    Half-Toon Hero!

  • New Member
  • 340 posts

Posted 21 January 2007 - 02:58 AM

I see you finally busted the double problem :D.

This DLL is great, not long time ago I saw a topic where a member asked how to prevent the user to open two instances of a game. There were many good suggestions but this should be the safest one.

Good work <_<!

<{POST_SNAPBACK}>


Thanks; Yeah like 3 days ago I busted that problem (although I didn't use double data type here). I'm not sure if users are requesting this sort of stuff now. I thought it was like a very long time ago. Then again, this DLL is just a useful example. I'm not sure if this was the safest too but I already seen a source code of an application do that.

I updated the DLL to fix some bug where it never returned -2. And the DLL size is back to the 2.5kb (not that anyone should care) due to the fact I made the variable ToonMutex an uninitialized data. Although I could be wrong about doing it that way.

Now (maybe previous too) the checking didn't work properly. I added sleep(0); after the external call so it did get the value of _ret (some odd reason it never returned -1). I also tried fwait, but never worked. But I'll leave that in case of anything.

If the new version doesn't work and the old one did I'll put that back and start scratch from there.

- Toon-Master

EDIT: If you run it both quick I think it is bypassed :\ It still happens though. Not sure how to fix it but I'll try something else.

EDIT2: I added a function to check the mutex again (ToonMutex variable). I don't know what's wrong but when I use external_call for the first time it didn't return right (somewhere true area) :/ But When I check the variable it only SEEMS to work. So I can't say if it's truely working, but it's working so far. Redownload the package if already downloaded this.

Edited by Toon-Master, 21 January 2007 - 12:35 PM.

  • 0
D: I'm sorry if I'm unavailable for answering questions through messaging on GMC.
-------------------------------------------------------------------
I love Leanny Basil, Heart on Artivale. You inspired me for so many years.

#4 Sajty

Sajty

    GMC Member

  • New Member
  • 34 posts

Posted 11 February 2007 - 02:18 PM

Interesting source code and every line commented!
Great work!

To write something in asm is too much work!
I never tried it :D
I use w32dasm to crack exe files.
  • 0

#5 Radical_games_and_apps

Radical_games_and_apps

    GMC Member

  • New Member
  • 2 posts

Posted 27 February 2011 - 06:24 PM

Sorry for bumping this old topic, but it seems to be very handy...
I'm making a mediaplayer (yes, again...) and it works, but when opening music files from the windows explorer the mediaplayer multiplies it self...
I have tried making a system using ini files, having a game_end event which frees the ini, but when the mediaplayer noticed it was run twice it, err game-ended and set the ini to free...
making it useless if the user opened more then 1 music file......... :(
I've now come across this, but to my disapointment it's not working...
The exe says that it will not run twice, but i can start 10 exact same versions of it without getting any message or signal that it is run twice...
Even altered the code to just abort when run twice, but nothing happened.
Does anyone know a solution to this?
Other dll which is being updated and followed at this time or a fix for this one?

RGA

@Dark Matter: Yeah guess you're right...
Got a litlle excited about this dll since it would do exactly what I wanted...

Edited by Radical_games_and_apps, 27 February 2011 - 09:23 PM.

  • 0

#6 Dark Matter

Dark Matter

    RPG Expert

  • GMC Member
  • 3196 posts
  • Version:GM:Studio

Posted 27 February 2011 - 07:17 PM

Sorry for bumping this old topic, but it seems to be very handy...

A 4 year one. It's generally not a good idea to bump topics like that. Just PM Toon-Master instead (if he's still active).
  • 0
String Distortion (Now Staff Picked!)

The .gmx format disassembly

I'm always happy to help with a problem or question you have regarding Game Maker. Feel free to ask me anything you want!