473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Late Binding to a Imported Interface

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
1 2817
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mia lanui | last post by:
I have 3 C#.NET assemblies: Assembly A: Calls methods of Assembly C, which implements an interface in Assembly B, therefore, must reference both B and C (unless late binding is used) Assembly...
5
by: Daniel Bass | last post by:
..Net is great for modulerising libraries, so that all you need do to access a DLL, is simply call Add Reference and wallah, it's as though the library were written in your project. But what...
9
by: Scott English | last post by:
I am writing an C# program. I call a method on a COM object that returns Object. I don't know the type of the object (and reflection just says its a __ComObject), but I know there is supposed to...
1
by: Jim | last post by:
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...
2
by: cmrchs | last post by:
Hi, is it possible to instantiate an object on a remote server using late-binding ? (so the client does not need the info at compile time.) I look at remoting, but all those methods 'force'...
5
by: CodeRazor | last post by:
How can i load an interface from a dll using System.Reflection? I can see how its possible to do this on methods, properties in a class. You create an instance of the class and use the invoke...
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
2
by: Wonder | last post by:
Hi all, I have two objects in my COM+ that I can't add the references to my project. It has to use late binding in C#. For my applications in vb.net, I can solve the problem using the code...
4
by: Rippo | last post by:
Hi I have the following console application and am attempting to late bind a class with option strict on! However of course I cant and I get the following error "Option Strict On disallows late...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.