B
Ben Harper
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.
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.