Reputation: 21
I have a C++ class in my 3rd party dll.
If I call Assembly.LoadFrom(), VS throws up an unhandled exception as there is no manifest contained in the module.
I can call global functions using DllImport to get an instance of a certain class.
How do I then call one of its member functions?
Upvotes: 2
Views: 926
Reputation: 8881
Create a wrapper DLL with C++/CLI exposing C++ functions
for example:
//class in the 3rd party dll
class NativeClass
{
public:
int NativeMethod(int a)
{
return 1;
}
};
//wrapper for the NativeClass
class ref RefClass
{
NativeClass * m_pNative;
public:
RefClass():m_pNative(NULL)
{
m_pNative = new NativeClass();
}
int WrapperForNativeMethod(int a)
{
return m_pNative->NativeMethod(a);
}
~RefClass()
{
this->!RefClass();
}
//Finalizer
!RefClass()
{
delete m_pNative;
m_pNative = NULL;
}
};
Upvotes: 2