Q
Quinn Tyler Jackson
Hello:
This question relates both to C# and to unmanaged C++, but is not really "C#
specific" at the C# end.
Let us suppose that I have a C# class such that:
using System;
using SomeCOM_Lib;
namespace Foo
{
class Bar : SomeCOM_Lib.ISomeInterface
{
public void SomeMethod() {}
}
class Quux
{
public void SomeCSharpMethod()
{
SomeCOM_Lib.ISomeOtherInterface obj = new
SomeCOM_Lib.ISomeOtherInterface();
obj.TheInterface = obj;
}
}
}
Now, let us suppose in our C++, the put_TheInterface on ISomeOtherInterface
wishes to query TheInterface for the methods of Bar, via the base interface
ISomeInterface (which includes an IDispatch interface).
In other words, from unmanaged C++, given the IDispatch interface of the C#
"obj" -- is there a way to determine the names of the methods on obj, such
that "SomeMethod" can be identified and its ID queried, so it can be invoked
off IDispatch::Invoke?
Essentially, I wish to determine at run-time the methods of a C# class and
call them via IDispatch, without knowing in advance (at compile time) what
those methods are named.
This is to implement a generic "callback" functionality.
Thanks in advance for any pointers.
(At the C++ side, the code should not require the assumption that the .NET
framework is installed. The C# class could, in fact, have been implemented
in unmanaged C++, but in this case just happens to be in C#.)
This question relates both to C# and to unmanaged C++, but is not really "C#
specific" at the C# end.
Let us suppose that I have a C# class such that:
using System;
using SomeCOM_Lib;
namespace Foo
{
class Bar : SomeCOM_Lib.ISomeInterface
{
public void SomeMethod() {}
}
class Quux
{
public void SomeCSharpMethod()
{
SomeCOM_Lib.ISomeOtherInterface obj = new
SomeCOM_Lib.ISomeOtherInterface();
obj.TheInterface = obj;
}
}
}
Now, let us suppose in our C++, the put_TheInterface on ISomeOtherInterface
wishes to query TheInterface for the methods of Bar, via the base interface
ISomeInterface (which includes an IDispatch interface).
In other words, from unmanaged C++, given the IDispatch interface of the C#
"obj" -- is there a way to determine the names of the methods on obj, such
that "SomeMethod" can be identified and its ID queried, so it can be invoked
off IDispatch::Invoke?
Essentially, I wish to determine at run-time the methods of a C# class and
call them via IDispatch, without knowing in advance (at compile time) what
those methods are named.
This is to implement a generic "callback" functionality.
Thanks in advance for any pointers.
(At the C++ side, the code should not require the assumption that the .NET
framework is installed. The C# class could, in fact, have been implemented
in unmanaged C++, but in this case just happens to be in C#.)