|
-
Oct 7th, 2013, 06:27 PM
#1
Thread Starter
Frenzied Member
Attach to running instance of application via process
I am working on an app to interface with a CAD program. What I would like to do is not only create a new application object, but add ability attach to a current running instance. I can create the object like this:
Code:
Dim rhinoApp As Rhino5x64Application
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
rhinoApp = New Rhino5x64Application()
rhinoApp.Visible = True
Catch ex As Exception
MessageBox.Show("Could not create Rhino Application!", "Error Creating Object!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
I can detect the current running instances of the application like so:
Code:
For Each p In Process.GetProcessesByName("Rhino4")
ListBox1.Items.Add(p.ProcessName & " - " & p.MainWindowTitle)
Next p
Question is, how do I assign the process to an object so i can ctype it to an instance of my application? Pseudo-code sort of like
Code:
Try
Dim prc As process = myprocess
Dim rhinoScriptingObject = CType(prc, Rhino5x64Application)
Catch ex As Exception
MessageBox.Show("Could not create scripting object! Make sure that Rhino is instantiated already", "Error Instantiating Scripting!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Last edited by jayinthe813; Oct 7th, 2013 at 06:31 PM.
-
Oct 7th, 2013, 10:57 PM
#2
Fanatic Member
Re: Attach to running instance of application via process
Hi,
i know you can manipulate another program using API, and grab references to it with code but to access it and manipulate it directly i think is going to be a tough job, unless it has be designed with this in mind you will basically have to hack it open.
maybe one of the other guys has more insight.
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work

-
Oct 7th, 2013, 11:18 PM
#3
Thread Starter
Frenzied Member
Re: Attach to running instance of application via process
 Originally Posted by GBeats
Hi,
i know you can manipulate another program using API, and grab references to it with code but to access it and manipulate it directly i think is going to be a tough job, unless it has be designed with this in mind you will basically have to hack it open.
maybe one of the other guys has more insight.
I have seen getactiveobject but I do no think that's what I really looking to do. I would think somehow you could ctype() from existing application object (maybe through windows shell?) to the correct object interface. I can do this with internet explorer fairly easily, but I am having trouble with this...
-
Oct 8th, 2013, 05:40 AM
#4
Re: Attach to running instance of application via process
You obviously have an import for this Rhino5x64Application type object. This class would presumably be a wrapper around starting the process and holding onto the stdin/stdout amongst possibly other things. If you wanted to try to connect to an existing process (started directly by the user?) then this wrapper would not exist, so you would have no method to get hold of it.
You would have to find out how this Rhino5x64Application library starts the process, how and what it does to connect to it, and then somehow workout if connecting to the app in the same way is even possible while it is already running..... Good luck
-
Jan 8th, 2015, 08:27 AM
#5
New Member
Re: Attach to running instance of application via process
jayinthe813, did you succeed to RunScript on an already open instance of Rhino? Once you get the process id how can you do?
-
Jan 9th, 2015, 06:18 PM
#6
Thread Starter
Frenzied Member
Re: Attach to running instance of application via process
 Originally Posted by Lore
jayinthe813, did you succeed to RunScript on an already open instance of Rhino? Once you get the process id how can you do?
No, I was unable to attach to an existing instance of Rhino, so I just created a new instance a runtime instead. For my needs attaching to an existing rhino instance was a nice to have but not necessary. I tried a bunch of stuff but couldn't get it to work. You could try asking on the McNeel forum:
http://discourse.mcneel.com/
-
Jan 9th, 2015, 06:35 PM
#7
Re: Attach to running instance of application via process
What is Rhino5x64Application(), why would you loop processes to detect instances when the functionality is already provided for you. Is there a reason you are not using My.Application.StartupNextInstance Event?
-
Jan 9th, 2015, 07:03 PM
#8
Re: Attach to running instance of application via process
IT sounds like this Rhino5x64Application is a thrid-party application... and the .NET application is attempting to attach to it... much like you can do with attaching to a running instance of Word or Excel, or Internet Explorer... so My.Application.StartupNextInstance isn't appropriate.
-tg
-
Jan 9th, 2015, 07:06 PM
#9
Re: Attach to running instance of application via process
 Originally Posted by techgnome
IT sounds like this Rhino5x64Application is a thrid-party application... and the .NET application is attempting to attach to it... much like you can do with attaching to a running instance of Word or Excel, or Internet Explorer... so My.Application.StartupNextInstance isn't appropriate.
-tg
That explains it if true. Thanks TG
-
Jan 9th, 2015, 07:41 PM
#10
Thread Starter
Frenzied Member
Re: Attach to running instance of application via process
 Originally Posted by ident
What is Rhino5x64Application(), why would you loop processes to detect instances when the functionality is already provided for you. Is there a reason you are not using My.Application.StartupNextInstance Event?
Rhino is a 3D modeling application. Rhino5x64Application() is the class in the DLL that you use to create a new instance of the application. It is found in a DLL that is referenced from the COM tab. It is similar to something like Excel Interop. It lets you control Rhino from outside of the actual application to perform automation.
The purpose of doing this would be to let someone work in the application, then launch a .NET app, attach to the instance using process name and run some automation or something. I found its just as easy to create the instance from .NET application, work in it, then run the automation from the app.
 Originally Posted by techgnome
IT sounds like this Rhino5x64Application is a thrid-party application... and the .NET application is attempting to attach to it... much like you can do with attaching to a running instance of Word or Excel, or Internet Explorer... so My.Application.StartupNextInstance isn't appropriate.
-tg
I have no idea still what is the appropriate way, but this was an old project and I don't feel like posting over on the dev forums.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|