1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
// Loader.cpp : main project file.
#using <mscorlib.dll>
#using <System.dll>
#include <vcclr.h>
#include <stdio.h>
#include <tchar.h>
using namespace System;
using namespace System::Reflection;
int main(array<System::String ^> ^args)
{
try {
// Load library dynamically:
Assembly* a = Assembly::Load("CPlugin");
if (a) {
Console::WriteLine("Assembly = {0}", a);
Type* t = a->GetType("MyLib.MyClass");
if (t) {
Console::WriteLine("Type = {0}", t);
MethodInfo* m = t->GetMethod("SayHello");
if (m) {
Console::WriteLine("Method = {0}\n", m);
String* args[] = {"Test2"};
m->Invoke(NULL, args);
} else {
printf("Can't find SayHello!\n");
}
} else {
printf("Can't find MyLib.MyClass!\n");
}
} else {
printf("Can't load MyLib!\n");
}
} catch (Exception* e) {
Console::WriteLine("*** Oops: Exception occurred: {0}", e);
}
return 0;
} |
Partager