473,320 Members | 1,876 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.

broken cast operator

I define an interface in managed C++: I call it ISgPlugin.
I implement that interface in a C# dll:
Using reflection, I try to load and instantiate that interface from the C++
module. I get far, but not far enough:

I use type->GetInterface( S"ISgPlugin" ) to get the type of a class inside
the C# dll that implements
ISgPlugin. That works.

I then use type->GetConstructor() to get an appropriate constructor for that
class. That works.

I invoke the constructor. That works. I now have an instance of the precise
class I am looking for: A class
derived from ISgPlugin- so the rest should be trivial.

I try and cast the instance I just created to ISgPlugin. That Fails.

I have absolutely no idea why this is. I have checked the C# dll in ildasm
and it appears fine- ie. it appears to implement ISgPlugin.
Everything else works, except for that last step. I am really dying for a
C-style cast here, but unfortunately that is no longer possible.
This looks to me like a bug in the compiler or runtime.
I have used the exact same method in a C# hosted dll, and it works
perfectly.

Anybody have any suggestions?
I am very very tired of this kind of thing.... I heard one MSFT
representative say recently at a conference, that they like implementing
features where one can say of it that "It Just Works". Well I am getting
pretty bloody tired of Managed C++, it seems too many parts of it "Just
Don't Work".

That said- I would love any help or suggestions.
.........
Ben.
Nov 16 '05 #1
1 1139
Please ignore this post.

My error was that I had my dll in the GAC, and two instances of it
were being loaded.
"Ben Harper" <be*@gls.co.za> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I define an interface in managed C++: I call it ISgPlugin.
I implement that interface in a C# dll:
Using reflection, I try to load and instantiate that interface from the C++ module. I get far, but not far enough:

I use type->GetInterface( S"ISgPlugin" ) to get the type of a class inside
the C# dll that implements
ISgPlugin. That works.

I then use type->GetConstructor() to get an appropriate constructor for that class. That works.

I invoke the constructor. That works. I now have an instance of the precise class I am looking for: A class
derived from ISgPlugin- so the rest should be trivial.

I try and cast the instance I just created to ISgPlugin. That Fails.

I have absolutely no idea why this is. I have checked the C# dll in ildasm
and it appears fine- ie. it appears to implement ISgPlugin.
Everything else works, except for that last step. I am really dying for a
C-style cast here, but unfortunately that is no longer possible.
This looks to me like a bug in the compiler or runtime.
I have used the exact same method in a C# hosted dll, and it works
perfectly.

Anybody have any suggestions?
I am very very tired of this kind of thing.... I heard one MSFT
representative say recently at a conference, that they like implementing
features where one can say of it that "It Just Works". Well I am getting
pretty bloody tired of Managed C++, it seems too many parts of it "Just
Don't Work".

That said- I would love any help or suggestions.
........
Ben.

Nov 16 '05 #2

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

Similar topics

2
by: Ulrich Heinen | last post by:
Let's say I have two classes A and B with similar goals but completely different implementations. In my application code I want to use class A exclusively, but instances of B should also be...
0
by: A. W. Dunstan | last post by:
I'm porting some code to Visual C++ and have run into a problem - the compiler won't use a user-written cast operator. The code uses an envelope-letter approach to passing (potentially) large...
7
by: Arno | last post by:
Hello, I want to write classes, which can be used as interchangeably as possible. The background is that they are smartpointers, which should implicitly cast between each other. As a toy...
7
by: pnsteiner | last post by:
i want to use the << operator defined for ostream with an object that itself knows nothing of the operator, but is castable to ostream&. it seems that C++ doesn't do implicit casts before invoking...
8
by: GlennDoten | last post by:
I just happened to be looking through the implementation of the System.Version class in the SSCLI and one of the constructors starts like this: public Version(String version) { if ((Object)...
5
by: Frederick Gotham | last post by:
Before I begin, here's a list of assumptions for this particular example: (1) unsigned int has no padding bits, and therefore no invalid bit- patterns or trap representations. (2) All types have...
2
by: groups | last post by:
C# is an impressive language...but it seems to have one big limitation that, from a C++ background, seems unacceptable. Here's the problem: I have a third-party Document class. (This means I...
16
by: JoseMariaSola | last post by:
How may operators and operands does (typename) expression has? I'd say one operator, the cast operator, and two operands: typename and expression. But everywhere I read, cast is categorized as...
7
by: * Tong * | last post by:
Hi, I couldn't figure out how to properly type cast in this case: $ cat -n type_cast.c 1 #include <stdio.h> 2 3 typedef unsigned char Byte; 4 typedef signed char Small_Int; 5
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: 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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.