Visual C++ .NET/Reflection/Assembly
Get type from Assembly
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
ref class Reflector
{
public:
void TestDynamicCall(String^ greeting)
{
Console::WriteLine(greeting);
}
};
void LoadAndReflect(String^ assemblyFileName, String^ typeName,String^ methodName, array<Object^>^ parameterList)
{
Assembly^ assembly = Assembly::LoadFrom(assemblyFileName);
Type^ t= assembly->GetType(typeName);
MethodInfo^ method = t->GetMethod(methodName);
Object^ obj = Activator::CreateInstance(t);
method->Invoke(obj, parameterList);
}
int main()
{
array<Object^>^ params = gcnew array<Object^> { "Hello!" };
LoadAndReflect("reflection2.exe", "Reflector", "TestDynamicCall", params);
}
Load Assembly from exe file
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
ref class Reflector
{
public:
void TestDynamicCall(String^ greeting)
{
Console::WriteLine(greeting);
}
};
void LoadAndReflect(String^ assemblyFileName, String^ typeName,String^ methodName, array<Object^>^ parameterList)
{
Assembly^ assembly = Assembly::LoadFrom(assemblyFileName);
Type^ t= assembly->GetType(typeName);
MethodInfo^ method = t->GetMethod(methodName);
Object^ obj = Activator::CreateInstance(t);
method->Invoke(obj, parameterList);
}
int main()
{
array<Object^>^ params = gcnew array<Object^> { "Hello!" };
LoadAndReflect("reflection2.exe", "Reflector", "TestDynamicCall", params);
}