Accessing ActiveX EXE via C # Forms Application

  • Thread starter Thread starter Amernauth
  • Start date Start date
A

Amernauth

Guest
Hello,

I've been trying to get a handle on how to accomplish accessing an ActiveX EXE's methods from a C# Application but still a little confused.

I scoured the internet and saw posts regarding using GetActiveObject but then I saw mention of using the GAC so this raised some questions whether my implementation is correct or not.

Here is what I've done this far ..

  1. Created a Net DLL by calling tlbmip
  2. Added the newly created .dll as a reference in my C# Forms project
  3. Then I use the reflection services to call the exposed methods .. Example ..

Process p = Process.Start("test.exe");
p.WaitForInputIdle();
Assembly assembly = Assembly.LoadFile("C:\\Test\\bin\\Debug\\test.dll");
Type type = assembly.GetType("test.DocumentClass");
var methodInfo = type.GetMethod("RetrieveStatus");
if (methodInfo == null)
{
// never throw generic Exception - replace this with some other exception type
throw new Exception("No such method exists.");
}

dynamic instance = Activator.CreateInstance(type);
var response = instance.RetrieveStatus();
MessageBox.Show(string.Format("Value returned from RetrieveStatus {0}", response), "ReturnVal", MessageBoxButtons.OK);

This returns a valid value but not sure if it's the correct way to be doing this?

Do I need to register the ActiveX EXE? I see posts regarding using Regasm.

Is my newly created dll in fact communicating with the ActiveX EXE?

Do I need my ActiveX EXE invoked or can I exclusively just use the dll now?

Thanks!

Continue reading...
 
Back
Top