E
ewpatton
Hi,
I have written a DLL in C++.NET that contains a class inherited from a
single abstraction:
//------ IThing.h ------
#ifndef __ITHING_H__
#define __ITHING_H__
namespace DLLObject
{
public interface class IThing {
System::String ^DoTest();
};
}
#endif
//------ Thing.h ------
#ifndef __THING_H__
#define __THING_H__
#include "IThing.h"
namespace DLLObject
{
public ref class Thing : public IThing {
virtual System::String ^DoTest();
};
}
#endif
//------ Thing.cpp ------
#include "Thing.h"
namespace DLLObject
{
using namespace System;
String ^Thing:oTest() { return "Test"; }
}
Now I want to be able to access this class dynamically at runtime
(since it's assumed other people will make their own IThings.) since I
don't want to have to recompile every time I add a new custom object.
I found a sample online and attempted to mimic it in my own program:
Form1()
{
Reflection::Assembly ^myasm = Reflection::Assembly::LoadFrom("..\
\Debug\\DLLObject.dll");
Object ^obj;
IThing ^thing;
obj = myasm->CreateInstance("DLLObject.Thing", true);
thing = safe_cast<IThing ^>(obj);
MessageBox::Show(thing->GetName());
}
However, when I attempt to run this program an exception is thrown
stating that .NET can't cast an object of type DLLObject.Thing to
DLLObject.IThing. Can anyone give me any pointers on what I'm doing
wrong?
I can supply the sample solution if necessary.
Evan
I have written a DLL in C++.NET that contains a class inherited from a
single abstraction:
//------ IThing.h ------
#ifndef __ITHING_H__
#define __ITHING_H__
namespace DLLObject
{
public interface class IThing {
System::String ^DoTest();
};
}
#endif
//------ Thing.h ------
#ifndef __THING_H__
#define __THING_H__
#include "IThing.h"
namespace DLLObject
{
public ref class Thing : public IThing {
virtual System::String ^DoTest();
};
}
#endif
//------ Thing.cpp ------
#include "Thing.h"
namespace DLLObject
{
using namespace System;
String ^Thing:oTest() { return "Test"; }
}
Now I want to be able to access this class dynamically at runtime
(since it's assumed other people will make their own IThings.) since I
don't want to have to recompile every time I add a new custom object.
I found a sample online and attempted to mimic it in my own program:
Form1()
{
Reflection::Assembly ^myasm = Reflection::Assembly::LoadFrom("..\
\Debug\\DLLObject.dll");
Object ^obj;
IThing ^thing;
obj = myasm->CreateInstance("DLLObject.Thing", true);
thing = safe_cast<IThing ^>(obj);
MessageBox::Show(thing->GetName());
}
However, when I attempt to run this program an exception is thrown
stating that .NET can't cast an object of type DLLObject.Thing to
DLLObject.IThing. Can anyone give me any pointers on what I'm doing
wrong?
I can supply the sample solution if necessary.
Evan