July 07, 2024, 03:20:50 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Single Instance For Ebasic Howto

Started by rhuckle, April 26, 2008, 09:23:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rhuckle

Hi just requestinng basic demo (code) for ebasic that will allow a single instance of the application

i am a newbie to ebasic thus wouldnt know how to convert ibasic with that in mind i have never used ibasic ive ever only used ebasic for my needs

so any examples for how to achieve this will be greatly apreciated

regards

Ricky H.

Ionic Wind Support Team

I'll leave it to you to look up the API declares and constants...


UINT hMutexOneInstance:hMutexOneInstance = CreateMutexA( NULL, FALSE,"MYPROGRAMNAME-088FA840-B10E-11D7-BC31-006062709674")
INT gle:gle = _GetLastError()
if (gle = ERROR_ALREADY_EXISTS) OR (gle = ERROR_ACCESS_DENIED)
'program already open.  Terminate
MessageBox 0,"Program already running","Notice",@MB_ICONEXCLAMATION
End
endif


The string in CreateMutexA just has to be unique to the system.  You can use anything you want.  Just put that code in the beginning of you program, before you do anything else.

Paul.

Ionic Wind Support Team

rhuckle

hi thanks paul for the quick reply, now im also having one more issue i have  1 window called w and 3 dialogs called d1, d2 and d3

but i have tried every method to get the static text within the d1 dialog to set size say to 18 but it remains nomal size if i hoever have font set to the window which is w, the buttons text will change but this is not what im wanting im trying to change the dialog windows only not the window as that does not contain text it is just the container for the dialogs and buttons that open the dialogs

regards

Ricky H

rhuckle

Quote from: Paul Turley on April 26, 2008, 09:53:30 AM
I'll leave it to you to look up the API declares and constants...


UINT hMutexOneInstance:hMutexOneInstance = CreateMutexA( NULL, FALSE,"MYPROGRAMNAME-088FA840-B10E-11D7-BC31-006062709674")
INT gle:gle = _GetLastError()
if (gle = ERROR_ALREADY_EXISTS) OR (gle = ERROR_ACCESS_DENIED)
'program already open.  Terminate
MessageBox 0,"Program already running","Notice",@MB_ICONEXCLAMATION
End
endif


The string in CreateMutexA just has to be unique to the system.  You can use anything you want.  Just put that code in the beginning of you program, before you do anything else.

Paul.



i now have recieved this error

Compiling Resources...
No Errors

Compiling...
compile.eba
File: C:\apache2triad\htdocs\inc\javaServer\src\compile.eba (40) Warning: undeclared function 'CreateMutexA'
File: C:\apache2triad\htdocs\inc\javaServer\src\compile.eba (41) Warning: undeclared function '_GetLastError'
File: C:\apache2triad\htdocs\inc\javaServer\src\compile.eba (42) undefined variable - ERROR_ALREADY_EXISTS
File: C:\apache2triad\htdocs\inc\javaServer\src\compile.eba (42) Invalid comparison
File: C:\apache2triad\htdocs\inc\javaServer\src\compile.eba (42) undefined variable - ERROR_ACCESS_DENIED
File: C:\apache2triad\htdocs\inc\javaServer\src\compile.eba (42) Invalid comparison
Error(s) in compiling C:\apache2triad\htdocs\inc\javaServer\src\compile.eba
Build Failed

Ionic Wind Support Team

Like I said, I will leave it up to you to look up the API declares for the functions CreateMutexA and GetLastError.  MSDN or Google.  Here.....

Declare Import, CreateMutexA(lpMutexAttributes AS Pointer,bInitialOwner AS INT,lpName AS POINTER),INT
Declare Import, _GetLastError alias GetLastError(),INT

CONST ERROR_ALREADY_EXISTS = 183
CONST ERROR_ACCESS_DENIED = 5
Ionic Wind Support Team

rhuckle

Quote from: Paul Turley on April 26, 2008, 10:18:53 AM
Like I said, I will leave it up to you to look up the API declares for the functions CreateMutexA and GetLastError.  MSDN or Google.  Here.....

Declare Import, CreateMutexA(lpMutexAttributes AS Pointer,bInitialOwner AS INT,lpName AS POINTER),INT
Declare Import, _GetLastError alias GetLastError(),INT

CONST ERROR_ALREADY_EXISTS = 183
CONST ERROR_ACCESS_DENIED = 5


that seemd to have done the trick, i know i have seen references to this window api on msdn etc but i have never found the right stuff microsoft site is all jargon to me unless i gota direct link to correct info :)

but thanks for the advise, just little tired and finaly happy i have now finished this leg of the app, which i spent all day trying to figure otu and you managed in couple seconds

so i congratulate you once again thanks

pistol350

Regards,

Peter B.

Locodarwin

Here's a subroutine version of the above code, suitable for eventual command submission:


' Uncomment the following code for testing purposes
' And be sure to attempt to run the resulting EXE twice, simultaneously

/*
Dim iSuccess As INT
Dim sMutex As STRING

sMutex = "La la la random string"

Print "Checking to see if the program is already running..."
iSuccess = SingleInstance(sMutex)

If iSuccess Then
Print "Program is already running."
Else
Print "This is the only instance running."
EndIf

Print:Print "Press any key to close"
Do:Until Inkey$<>""
End
*/


'============================================================================================
'
' Description: Check to see if an instance of the current program is already running.
' Syntax: SingleInstance(sOccurName)
' Parameters: sOccurName - String to identify the mutual exclusion (can be anything unique to the system)
' Return values: If an instance is running - Returns 1
' If an instance is not running - Returns 0
' Author(s): Paul Turley, SEO (locodarwin at yahoo dot com)
' Note(s): Call this sub as soon as the program starts if you intend to only allow one
' running instance of your program at a time.
'
' ===========================================================================================
Sub SingleInstance(sOccurName as STRING), INT

UINT hMutexOneInstance
INT LastErr

Declare Import, CreateMutexA(lpMutexAttributes AS POINTER, bInitialOwner AS INT, lpName AS POINTER), INT
Declare Import, _GetLastError alias GetLastError(), INT

hMutexOneInstance = CreateMutexA(NULL, FALSE, sOccurName)
LastErr = _GetLastError()
If (LastErr = 183) Or (LastErr = 5) Then
Return 1
Else
Return 0
EndIf
EndSub


Enjoy!

-S