Late Binding to a Imported Interface

G

Guest

Hey all

I'm trying to late bind a VB6 object in Component Services using c#. I've been able to do tons of late binding, but now that I have a com+ object that doesn't have a method exposed directly, I'm having tons of trouble. (lots of research, lots of newsgroups, but no success!

I have an existing COM+ object "Company.Person" which has several interfaces. To load my object, I have to invoke a method that is "Imported" to "Person", the main interface (via the imported interface, IUser).

When late binding, this interface doesn't appear to be accessible. How do I invoke the "Load" method on IUser to populate my Company.Person object

Attempted Code

Type myUserType= Type.GetTypeFromProgID("Company.Person")
object objMyUser = Activator.CreateInstance(myUserType)

// parameters needed to load objMyUse
object[] parameter = new object[2]
parameter[0]=m_strDBConn
parameter[1]="GeorgePBurdell";

//I've tried this with 8 gazillion different BindingFlags combinations...
// I haven't found any great docs on the differences between the flag
myUserType.InvokeMember("Load"
BindingFlags.Public | BindingFlags.Static
BindingFlags.NonPublic |BindingFlags.Instance | BindingFlags.DeclaredOnly
BindingFlags.InvokeMethod, null, objMyUser, parameter)

When I try to InvokeMember on the "Load" command, I get the dreaded mscorlib.dll error, with the extremely helpful, "unknown name" description

Any code snippets would be great
Thanks
Jim
 
G

Guest

From a contact at Microsoft:

"...if I read this right, he’s trying to late bind to a non-default interface. <b>You can’t do that</b>. Well, you can, but you have to hack the com object image, and that’s a bad idea.

For this kind of thing, the easiest solution is probably to build a broker class in VB6, hang a public method off of it, and let that public method QI and call Load on the other component. Call it a poor man’s class factory. May not be overly elegant, but for these kinds of issues, its usually easier to just drop a layer in there."

----- Jim wrote: -----

Hey all,

I'm trying to late bind a VB6 object in Component Services using c#. I've been able to do tons of late binding, but now that I have a com+ object that doesn't have a method exposed directly, I'm having tons of trouble. (lots of research, lots of newsgroups, but no success!)

I have an existing COM+ object "Company.Person" which has several interfaces. To load my object, I have to invoke a method that is "Imported" to "Person", the main interface (via the imported interface, IUser).

When late binding, this interface doesn't appear to be accessible. How do I invoke the "Load" method on IUser to populate my Company.Person object?

Attempted Code:

Type myUserType= Type.GetTypeFromProgID("Company.Person");
object objMyUser = Activator.CreateInstance(myUserType);

// parameters needed to load objMyUser
object[] parameter = new object[2];
parameter[0]=m_strDBConn;
parameter[1]="GeorgePBurdell";

//I've tried this with 8 gazillion different BindingFlags combinations....
// I haven't found any great docs on the differences between the flags
myUserType.InvokeMember("Load",
BindingFlags.Public | BindingFlags.Static |
BindingFlags.NonPublic |BindingFlags.Instance | BindingFlags.DeclaredOnly |
BindingFlags.InvokeMethod, null, objMyUser, parameter);


When I try to InvokeMember on the "Load" command, I get the dreaded mscorlib.dll error, with the extremely helpful, "unknown name" description.

Any code snippets would be great.
Thanks,
Jim
 

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