473,385 Members | 2,003 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.

Passing an interface pointer through MethodInfo.Invoke

Our app is mainly COM based. We allow .NET plug-ins. When a plug-in is
installed, it receives a COM pointer to the app. The plug-in implements our
IExtensionImpl interface and gets the app pointer through the OnCreate
method...

public void OnCreate(IApplication pApp)...

The plug-in that I'm working on also allows sub-plug-ins. These
sub-plug-ins are simple DLLs that provide methods that are accessed via
Reflection.

Here's my problem... I need to forward the IApplication pointer to the
sub-plug-in. Here's the sub-plug-in Create routine...

public void Create(IApplication app)...

The plug-in calls the sub-plug-in using the following Reflection code...

MethodInfo method = Reflect.GetNamedMethod(type, "Create",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
Object[] parameters = new Object[1] { m_app }; // m_app was
cached in OnCreate()
Type t1 = parameters[0].GetType();
Type t2 = method.GetParameters()[0].ParameterType;
method.Invoke(testType, parameters);

The Invoke fails with a type mismatch:

t1 = System.__ComObject
t2 = IApplication

How do I get the types to match?

Nov 8 '06 #1
2 3009
http://www.mztools.com/articles/2006/MZ013.htm
http://support.microsoft.com/?kbid=320523

"John Lutz" wrote:
Our app is mainly COM based. We allow .NET plug-ins. When a plug-in is
installed, it receives a COM pointer to the app. The plug-in implements our
IExtensionImpl interface and gets the app pointer through the OnCreate
method...

public void OnCreate(IApplication pApp)...

The plug-in that I'm working on also allows sub-plug-ins. These
sub-plug-ins are simple DLLs that provide methods that are accessed via
Reflection.

Here's my problem... I need to forward the IApplication pointer to the
sub-plug-in. Here's the sub-plug-in Create routine...

public void Create(IApplication app)...

The plug-in calls the sub-plug-in using the following Reflection code...

MethodInfo method = Reflect.GetNamedMethod(type, "Create",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
Object[] parameters = new Object[1] { m_app }; // m_app was
cached in OnCreate()
Type t1 = parameters[0].GetType();
Type t2 = method.GetParameters()[0].ParameterType;
method.Invoke(testType, parameters);

The Invoke fails with a type mismatch:

t1 = System.__ComObject
t2 = IApplication

How do I get the types to match?
Nov 9 '06 #2
Thanks for the information. I tried the following:

Object[] parameters = new Object[1] { m_app as IApplication };

It didn't fix the problem. I still get a type mismatch exception. It
seems like I either need to make my reflected method have a signature like
this...

void Create(System.__ComObject app)

Or else figure out how to make the Object array constructor convert my
interface pointer to something other than System.__ComObject.

I looked at some of the Marshalling routines but I really want to keep
everything in-process.

"Shailen Sukul" wrote:
http://www.mztools.com/articles/2006/MZ013.htm
http://support.microsoft.com/?kbid=320523

"John Lutz" wrote:
Our app is mainly COM based. We allow .NET plug-ins. When a plug-in is
installed, it receives a COM pointer to the app. The plug-in implements our
IExtensionImpl interface and gets the app pointer through the OnCreate
method...

public void OnCreate(IApplication pApp)...

The plug-in that I'm working on also allows sub-plug-ins. These
sub-plug-ins are simple DLLs that provide methods that are accessed via
Reflection.

Here's my problem... I need to forward the IApplication pointer to the
sub-plug-in. Here's the sub-plug-in Create routine...

public void Create(IApplication app)...

The plug-in calls the sub-plug-in using the following Reflection code...

MethodInfo method = Reflect.GetNamedMethod(type, "Create",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
Object[] parameters = new Object[1] { m_app }; // m_app was
cached in OnCreate()
Type t1 = parameters[0].GetType();
Type t2 = method.GetParameters()[0].ParameterType;
method.Invoke(testType, parameters);

The Invoke fails with a type mismatch:

t1 = System.__ComObject
t2 = IApplication

How do I get the types to match?

Nov 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: KK | last post by:
Hi MCPP gurus' I have a small problem in parameter passing.This is my situation namespace Abc { public __gc class ClassAbc { public: String* Hello(String* str) {
6
by: Kevin Yu | last post by:
hi all is there a way to pass an interface as input parameter for a web method? since interface is not serializable, does that mean it's impossible to do that? Kevin
1
by: Marek | last post by:
Hi I need to call a native function in a C++ dll from my C#. The C++ function declaration is shown below. The C# code that I have been trying to perform the call is also shown below. All it is...
3
by: Me | last post by:
I am trying to figure out any issues with calling System.Reflection.MethodInfo.Invoke() when dealing with multiple threads. For instance.. Say I have a class that allows you to pass in a...
1
by: ian | last post by:
Hi, I can't find a solution to this, so I've brought it to the experts. Using reflection I can get a MethodInfo object pointing at an assembly's method. Where I have a MethodInfo object...
5
by: evaristobo | last post by:
i'm a bit confused here, a pointer is something aiming to an object, but a static class is not an object, nevertheless i would like to have the possibility of doing something like handling an...
0
by: hypeartist | last post by:
I need to create interface "on-the-fly" so it "reflects" some class (mainly it's properties). Here's how I do this: public class Transformer { private const TypeAttributes...
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
4
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i am looking for an example that shows how to implement a COM Interface (with events) and pass it to a Windows API Call via pointer. Since this is really new to me, i dont know where to...
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.