I have two windows applications that are running. I then launch and connect to a third application via a plugin. In the plugin, I am trying to invoke a method on one of the first two applications, i.e. that application is the target object for the invoke. Every example I can find creates a new instance first, and gets the object reference back from a call to Activator.CreateInstance. I want the instance that is already running. I can get the assembly using GetAssembly. From that I can loop through the members and get the type. How do I get the target object to use in the InvokeMember? Using GetObject(, ODTuner.Application) does not work and I want to stay away from COM anyway (It gives me the "ActiveX Cannot Create Component" error.
Dim odt As ODTuner
Dim asm As Assembly
Dim odtType As System.Type
'temporarily create a new instance to get the correct type
'this would not be necessary if I could get the object reference of the currently running ODTuner
Dim myodt As New ODTuner
odtType = myodt.GetType 'temporarily create a new instance to get the correct type
myodt = Nothing
asm = Assembly.GetAssembly(odtType) 'gets the currently loaded assembly (odtuner.exe)
Dim t As Type = Nothing
Dim Types(), TypeInfo As Type
Types = asm.GetExportedTypes()
For Each TypeInfo In Types
msg = msg & TypeInfo.Name & vbCrLf
MsgBox(TypeInfo.Name)
If TypeInfo.Name = "ODTuner" Then
t = TypeInfo
'Else
' t = Nothing
End If
Next
Dim Result As Object
Dim args() As Object
args = {"Filter_25354"}
Result = t.InvokeMember("ODExecute", BindingFlags.Public Or BindingFlags.InvokeMethod Or BindingFlags.Instance, Nothing, odt, args)
Basically, I need to know what to set odt equal to? If I do
Dim odt as New ODTuner
It does invoke ODExecute, but cannot do anything because the necessary data is in the already running instance. I tried setting odt = t (where t is the type), but when I do this I get an error saying that the "Object does not match target type"