473,320 Members | 2,146 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,320 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 2808
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.