Hi,
Someone told me that it's possible to call methods of classes made with VB6 or VC++ from C# using reflection...
After made some investigation it seems that it's really true, I really can make a call to a "old" method using a "new" language :)
So after gathering all the evidences I tried to build a pratical example.
When I try to make the call to the method an exception is thrown:
Unhandled Exception: System.Security.SecurityException: Request for the permission of type System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0
.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
at COMReflectionExample.Client.Main(String[] args)
The state of the failed permission was:
<IPermission class="System.Security.Permissions.SecurityPermiss ion, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode"/>
Here's the code:
It calls a method WhoAmI, that exists in the class ClassY made in ProjectX (made w/ VB6)
Code:
Type T = Type.GetTypeFromProgID("ProjectX.ClassY");
object o = Activator.CreateInstance(T);
object returnValue;
object [] arguments = new object[1];
arguments[0] = "Bob";
returnValue = T.InvokeMember("WhoAmI",
BindingFlags.InvokeMethod,
null,
o,
arguments);
Console.WriteLine(returnValue);
Console.ReadLine();
Thank You for the help,
LuÃs Pinho