Here is the information I mentioned previously:
-----------------------------------------------------------------------------
#9. The RUN command in ASPECT is not giving me the correct Task ID. How do I communicate between two instances of Procomm Plus 4.5x?
-----------------------------------------------------------------------------
This tip applies to Procomm Plus 4.x for Windows.
When using the RUN command, you can obtain the Task ID and you have noticed that it is the same for both instances of Procomm that are running. In fact, the ID obtained is not the Task ID, but the Process ID. No matter how many
instances of Procomm Plus you have running, they all have the same Process ID. So you cannot use the Task ID (or Process ID here) to access the other instances of Procomm.
The book states that you should be able to manipulate a second instance of PW4 by using a specific instance handle:
"use PW4xxxxx, where the digits xxxxx correspond to the unsigned integer value of Procomm Plus's instance handle. You can obtain this handle value from within the ASPECT script by using the run command to launch another instance of Procomm Plus. "
Of course, using the RUN command gets the wrong ID. Additionally, the documentation here is incorrect - the xxxxx has to be replaced by the Thread ID instead of the Task ID (or Process ID). Unfortunately, the Thread ID is not obtainable by ASPECT. Therefore, you find that you cannot manipulate separate instances through their
Task ID and you cannot manipulate more than two instances through DDE.
RESOLUTION:
1) The DDE can be used to access the second instance by using "PW4" as the handle. This seems to work as long as no more instances of Procomm are executed.
2) Write a DLL that makes a Win32 API call to obtain the Thread ID, thereby allowing ASPECT to directly access the multiple instances.
The following example demonstrates how to setup a DDE link with a second instance of Procomm Plus.
proc main
string pathname
integer pwhwnd
long pwchanid
pathname = $pwtaskpath ;Get PW's path.
addfilename pathname "PW4.EXE" ;Add Procomm's EXE.
if run pathname ;Run the program.
pause 2
pwhwnd = $mainwin ;Get the active window ID.
if ddeinit pwchanid "PW4" "System" pwhwnd ;Establish DDE connection.
usermsg "DDE channel successfully established!"
else
errormsg "Error initializing DDE channel"
endif
else ;Problems running program.
errormsg "Error running %s" pathname
endif
endproc
Note: This example requires that new instances of Procomm Plus must receive focus, at least long enough to grab the window ID of the new instance.
aspect@aspectscripting.com