By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

Late Binding to a Imported Interface

P: n/a
Jim
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
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Jim
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
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.