E
EdwardS
I would greatly appreciate some help on passing managed object into unmanaged
code.
I need to pass a reference (address of) of a managed class into unmanaged
code (written by a thrid party). The 3rd party unmanaged DLL will pass this
reference into standard Win32 unmanaged static callback function in my code.
Inside this unmanaged callback function I need to cast this unmnaged pointer
that I have received from 3rd party back into the reference to a managed
class, so I could use member variables and functions of that managed class.
I do not have source code for the third party DLL, but our applicatin was
working perfectly fine with that thrid party DLL when it was built with all
unmanaged C++ code.
Here is my managed C++ class declaration inside Wrapper.h:
namespace MyNamespace
{
public ref class Wrapper
{
unsigned long m_hSource;
public:
Wrapper();
bool SetupCallback();
};
}
Here is code inside Wrapper.cpp
unsigned long __stdcall CallBackFunc(const void * pData, unsigned Context )
{
gcroot<eWCamera_Canon::CanonWrapper^> cwThis;
// Here is the place in question for casting back into managed class
// use m_hSource to delegate to C# User Interface
}
bool MyNameSpace::Wrapper::SetupCallback()
{
unsigned int err;
// Registering callback with 3rd party DLL
err = RegisterCallback(CallBackFunc, this);
}
code.
I need to pass a reference (address of) of a managed class into unmanaged
code (written by a thrid party). The 3rd party unmanaged DLL will pass this
reference into standard Win32 unmanaged static callback function in my code.
Inside this unmanaged callback function I need to cast this unmnaged pointer
that I have received from 3rd party back into the reference to a managed
class, so I could use member variables and functions of that managed class.
I do not have source code for the third party DLL, but our applicatin was
working perfectly fine with that thrid party DLL when it was built with all
unmanaged C++ code.
Here is my managed C++ class declaration inside Wrapper.h:
namespace MyNamespace
{
public ref class Wrapper
{
unsigned long m_hSource;
public:
Wrapper();
bool SetupCallback();
};
}
Here is code inside Wrapper.cpp
unsigned long __stdcall CallBackFunc(const void * pData, unsigned Context )
{
gcroot<eWCamera_Canon::CanonWrapper^> cwThis;
// Here is the place in question for casting back into managed class
// use m_hSource to delegate to C# User Interface
}
bool MyNameSpace::Wrapper::SetupCallback()
{
unsigned int err;
// Registering callback with 3rd party DLL
err = RegisterCallback(CallBackFunc, this);
}