Silverfrost Forums

Welcome to our forums

How to use CreateMutEx?

27 May 2011 11:29 #8314

I want to have an installation package do a check for an existing running copy of the program, so it can warn the user to close the app before trying to do the install. I've been advised that the way to do this is to call CreateMutEx, which I've been trying to do, but it always returns 0 (with a GetlastError returning 998, if I put the call in a DLL, or 1305 if it's in the main EXE)

I've tried: IRET = CreateMutEx (0,.FALSE.,progname) IRET = CreateMutEx (NULL,.FALSE.,progname) IRET = CreateMutEx (NULL,.FALSE.,progname//CHAR(0)) IRET = CreateMutEx (NULL,LRET,progname) ! LRETLOGICAL*4=.FALSE. IRET = CreateMutEx (NULL,LRET,progname) ! LRETLOGICAL*1=.FALSE.

And various other combinations, always with the same result.

Has anyone successfully used this call from FTN95? What's the trick?

TIA

K

28 May 2011 9:15 #8327

OK, found the trick!

The problem is the STDCALL definition in the WIN32API.INS file:

STDCALL CREATEMUTEX 'CreateMutexA' (**REF**,VAL,STRING):INTEGER*4

Having the 'REF' in there makes it rather difficult to pass a NULL pointer as required by the API, when using this form of the call. Defining my own version, using a VAL, makes the call work:

STDCALL CREATEMUTEXK 'CreateMutexA' (**VAL**,VAL,STRING):INTEGER*4

K

31 May 2011 2:35 #8332

Kenny,

While I am prepared to believe that it is possible to write an installation program in FTN95 and Clearwin, I'm not sure that it is an easy or satisfying task. Indeed, I gave up even before writing a single line of code. Partly it was a fear that the task would be long and frustrating, but even more so, there are free tools to do the job.

I have discovered that I am not alone in using Jordan Russell's InnoSetup (just Google and you will find his site). Not least among the many plus points for this software is the creation of a single, packed, EXE file containing your whole application, DLLs, demo files, self-instuction Powerpoints, CHM help files and all the rest.

Eddie

Edit: You may even find this helpful even if you go your own way: http://www.jrsoftware.org/iskb.php?mutexsessions It looks like a foreign language to me!

E

1 Jun 2011 6:46 #8336

Indeed, it is InnoSetup that I am using (and it's rather good!), but in order to detect a running instance of my application when the installer runs, I need to use CreateMutEx in my application for the AppMutex directive in Innosetup to work, hence the original enquiry.

K

1 Jun 2011 11:07 #8338

Now I understand why so many installation routines ask you to close any relevant applications - their programmers haven't mastered this, have they?

Something else for me to add to my list of things I would like to understand ...

E

Please login to reply.