Accessing a running ActiveX C# Exe from WebBrowser

T

Tobias Maier

Hi

I want to start a C# ActiveX Exe with a parameter.
Now, start a WebBrowser. Within Html/javascript I initiate my component
und want to retrieve the parameter from the startet exe.

I have done this in VB6 with new ActiveXObject("name") and all works
correct.

Using C# or Vb.net it works different:

- When the WenBroser calls the Exe, it starts its own process (the 2't
exe is not shown in the Taskmanager, only in ProcessExplorer).

- It return on this problem the empty value

- in the Browser Instance I can use this 2't exe instance (can set and
get new value)

What can I do to get the parameter from the startet exe outside the
browser instance? (the instance with the given paramter)

I have not found how to implement GetObject. this could solve also my
problem.


Sample Javascript code:

var oCorrespondenceControl;
oCorrespondenceControl = new ActiveXObject("AppPort.PortHolder");
oCorrespondenceControl.Display();

Classes of the Project:

Program:
[STAThread]
public static void Main(string[] args)
ActiveXObject.PORT = arg.Trim().Substring(6);
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
Application.Run();
}


ActiveXObject:

[ProgId("AppPort.PortHolder")]
[ClassInterface(ClassInterfaceType.AutoDual),
ComSourceInterfaces(typeof(ControlEvents))] //Implementing interface
that will be visible from JS
[Guid("121C3E0E-DC6E-45dc-952B-A6617F0FAB42")]
[ComVisible(true)]
public class ActiveXObject : IObjectSafetyImpl

public ActiveXObject()
{
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
}

[ComVisible(true)]
public void Display()
{
MessageBox.Show(PORT);
}


Thank you
tobias
 
N

Nicholas Paldino [.NET/C# MVP]

Tobias,

I think that what you want is the static GetActiveObject on the Marshal
class in the System.Runtime.InteropServices namespace.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top