Passing an Active X object reference into C# and using it.

M

Mike H

I can't seem to figure out the right thing to search on, so I thought
I'd just provide an example and see if someone can point me to some
tips.

What I have is an Automation Server that has a method that will start
another automation server. These Activex automation servers that it
talks to require a specific interface that the calling server uses to
manage the child active x automation servers. This is all part of an
application architecture that is unchangable, thus I need to work
within the constraints.

Here is an pseudo example with VB6 (the apps native language)

The object manager requires an interface on each called object that
looks like:
Option Explicit

Public obObjMgr as Object

Public Function InitializeObject(byval ObjMgr as Object)
set obObjMgr = ObjMgr
end function

Then this allows our app to do something like:

procedure cmdPopCustomer(custid as string)

dim CustForm as Object
set CustForm = obObjMgr.LaunchChild(custProj.clsCustMaint)
CustForm.LoadCust(custid)
end sub

I can get a C# app to expose the interface so the Object Manager can
launch it. But I am not sure how to go about consuming the reference
to the object manager, or for that part, any object that might be
returned by calling a ActiveX objects methods.

Any help is appreciated.





In VB 6, this is how it works:

The EXE is loaded into memory and is the main "object manager". It
launches any other ActiveX server keeping track of a reference to each
activex object it launches. As part of the interface, it also passes
a reference to itself to the launched app, so that the launched app
has access to some system services. One of these system services is
requesting another Active X object to be launched.

So say I am an invoice screen and I right click on the Customer name,
options come up including customer maintenance. I can click on that
and the customer maintenance form will open and populate with the
customer id matching the invoice I was looking at.

This is done by the Invoice screen having an object that contains a
reference to the object manager. To pop the cust maintenance form we
dim oChildForm as object
set oChildForm = objMgr.GetChild(MaintCustProj.clsMaintCust)
oChildForm.NavigateTo(this.CustID)
 
N

Nicholas Paldino [.NET/C# MVP]

Mike,

In this case, you have an interface in the loosest sense of the word.
You really should have type libraries which define actual interfaces that
the objects expose.

If you are able to add the interfaces, you should, if anything, it helps
enforce your application architecture. With type libraries, you can create
a .NET interop assembly and then just cast to that interface in the
assembly, and it will work.

If you can't even add the proper interface, then you will need to use
Reflection, calling the methods using late binding.
 

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