I've got the following in my project. But I can run two instances of the program. Shouldn't the second instance be blocked?
Function FF_WINMAIN(ByVal hInstance As Dword, _
ByVal hPrevInstance As Dword, _
ByVal lpCmdLine As Asciiz Ptr, _
ByVal iCmdShow As Long) As Long
'If this function returns TRUE (non-zero) then the actual WinMain will exit
'thus ending the program. You can do program initialization in this function.
If FF_PrevInstance Then
MsgBox "Prev Instance exists"
Function = %True 'return %TRUE if you want the program to end.
Else
Function = %False
End If
'Function = %FALSE 'return %TRUE if you want the program to end.
End Function
I'm using PB9 on an XP SP3 box. Thanks. -- tom
Hi Tom,
I just created a quick test program and FF_PrevInstance worked as advertised.
I simply used the following code:
If FF_PrevInstance() = %TRUE Then
MsgBox "prev instance running"
Function = %TRUE
Exit Function
End If
You code looks like it should work as well. Maybe try compiling your project again, exit FireFly, and then try running the compiled EXE twice. Also, check the file date/time of your compiled EXE to be 100% sure that the EXE is actually being created during the compile and is not just an old EXE.
Please let me know how you make out with this.
Paul, thanks. Mea Culpa!
Previous iterations of my program were compiled without specifying a Code Output Directory in Project Properties. This put the EXE file in my project folder.
Last night I changed the Code Output Directory setting to specify a subfolder named "Release", located beneath the project folder.
This morning I implemented FF_PrevInstance() and assumed that the EXE I compiled would be located in the Project folder, along with the form layouts and the project definitions file itself, thinking that only source code would be stored in the Release subfolder.
Your reply prompted me to check the Release subfolder and lo and behold there sits a newer EXE, which behaves correctly when the user tries to run two instances at the same time.
Am I right to conclude that the form layouts and project definition files do not get "output" to the Release subfolder in my case? Is this how others arrange things? What's recommended? I ask because I'm a bit bewildered about how to identify all the pieces I'd have to assemble if I, for example, wanted to send you a copy of my project.
Thanks again for the prompt reply.
-- tom
Hi Tom,
Happy to hear you found the problem. :)
When I create applications, I always create a new, separate, subdirectory for the Project. Off of that directory, I create directories like Forms, Modules, Images, Release. When I create Forms, Modules, etc. then I save them in the appropriate directories. When you go to backup your project then all you need to do is zip up the base/root directory and specify to also zip subdirectories.
Actually, in FireFly 3, the directory structure is set for you when you create a new project (Forms/Modules/Images/Release).