Richard Robertson Posted January 5, 2009 Share Posted January 5, 2009 The first program isn't starting the second one. The user starts the program again, and they certainly aren't going to provide extra parameters. Link to comment Share on other sites More sharing options...
MilesAhead Posted January 5, 2009 Share Posted January 5, 2009 (edited) Sorry for the confusion. I've been reworking components controls and ActiveX that are all related. It turns out I changed it so that UserString is a published property. If you assign to it in the secondary instance before calling Execute() it will be copied to the shared memory. The demo just shows a usage from AutoIt. To use to fit your situation is up to the application developer. But the info transfer handled by the control includes: complete command tail as it looked on the command line, complete path to 2nd instance, and event handlers for things like if the Mutex creation fails, File Mapping fails etc.. Granted much more useful in a compile language IDE scenario. $paramStr = "" Global $mainInstance = False Global $usrString = "" Global $tt = ObjCreate("TellTailXControl1.TellTailX") If @error Then MsgBox(0, "test", "ObjCreate Failed") Exit EndIf $tt.MapFileName = "{261AE7CC-38A3-4C70-9057-3C4C4D3A47C5}" $tt.MutexName = "{8D24D263-CAF6-41EA-BA32-5514F8EF7851}" $tt.Enabled = True ; this should be assigned before Execute() $tt.UserString = "Clean up and quit" ;2nd instance copies command line info to Memory Mapped File and dies if AutoKill $tt.AutoKill = True If $tt.Execute() And Not $tt.GetErrorCode() Then $mainInstance = True Else ;do something in 2nd instance EndIf While $usrString <> "Clean up and quit" While Not $tt.CopyData() Sleep(50) Wend $usrString = $tt.UserString If $tt.GetParamCount() Then $paramStr = $tt.GetParamStr(1) EndIf WEnd MsgBox(0, "test", "2nd Instance ParamStr(1) is " & $paramStr) $tt = 0 Exit edit: As I look at it the control is much more suited to compiled environments. I like to use it if I can because it's pretty well debugged... esp. the shared memory transfer. It is a lot more awkward to use with AutoIt though. Prolly not the best choice in this situation. Edited January 6, 2009 by MilesAhead My Freeware Page Link to comment Share on other sites More sharing options...
TinyBoy Posted January 6, 2009 Share Posted January 6, 2009 I have to check the rest of your code, but the OnAutoItExit method is already very usefull! Thanks!Just run it twice and you'll see, that the first instance may be closed and then, the exitcode of first instance is executed. Tinyboy Link to comment Share on other sites More sharing options...
MilesAhead Posted January 6, 2009 Share Posted January 6, 2009 (edited) This script shows a bit more how you could use the control along the lines of Unix fork(). In this one we aren't concerned with command line params. Just using the Execute() method in the 2nd instance to send data to the 1st which is listening. CODE $usrStr = "" $mainInstance = False $tt = ObjCreate("TellTailXControl1.TellTailX") If @error Then MsgBox(0, "test", "ObjCreate() Failed") Exit EndIf $tt.MapFileName = "{261AE7CC-38A3-4C70-9057-3C4C4D3A47C5}" $tt.MutexName = "{8D24D263-CAF6-41EA-BA32-5514F8EF7851}" $tt.Enabled = True $tt.AutoKill = False If $tt.Execute() And Not $tt.GetErrorCode() Then $mainInstance = True ShellExecute(@ScriptFullPath) ;launch another copy for grins EndIf ;when I get here I know if I am in 1st or 2nd instance ;AutoKill is False so 2nd instance keeps running While $mainInstance While Not $tt.CopyData() Sleep(50) WEnd $usrStr = $tt.UserString If $usrStr = "quit" Then MsgBox(0, @ScriptName, "Main Instance: Got Quit Msg") ExitLoop EndIf WEnd If Not $mainInstance Then $tt.UserString = "quit" $tt.Execute() ;transfer data to shared memory MsgBox(0, @ScriptName, "2nd Instance: Sent Quit Msg") EndIf $tt = 0 Exit Edited January 7, 2009 by MilesAhead My Freeware Page Link to comment Share on other sites More sharing options...
MilesAhead Posted January 8, 2009 Share Posted January 8, 2009 (edited) Here's a link to .chm help with some demosTellTailHelpI've been using some form of this component or control sincearound 2001. So hopefully the major functions should bepretty bullet proof.It used to have a custom property page with .hlp support thatworked in VC++ 6 and VB 6 Dialog Editor, but MS hosed thatin some later version of Visual Studio!! At least the "drop onthe form" mechanism still works in Visual Studio 2008!! Of courseit works in Delphi 5 IDE. Don't know about later Delphi versionsbut if stuff works with ActiveX Controls then it should work withthis. edit: btw I included the .ocx in the just updated help zip file with instructions to install it directlyedit2: Just updated the .ocx to fix a trap if the UserString Property is read but no string was everassigned to it. Now it's initialized to the string "(empty)" to avoid the memory access error. Edited January 9, 2009 by MilesAhead My Freeware Page Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now