Native to Manage communication via callback interface

D

DaTurk

Hi,


I'm writing an application that has a native c++ layer, and a CLi/C++
layer above it. Above the CLi layer will be C# but that's not
relavent to this post. My question has to do with communicating
between the native layer to the CLi layer. Typically how I do this
is
this ...


**CLi/C++ Layer**


******************************
--> MTest.h


namespace Test
{
private delegate void TestDelegate(Int32);


public ref class Test
{
private:
GCHandle testHandle_;
TestDelegate^ testDelegate_;


UnmanagedTest* uTest_;


void init();
void registerNativeCallback();


void TestCallback(Int32);
public:
Test();
}



}


******************************

--> MTest.cpp


#include "Test.h"


using namespace Test;


Test::Test()
{
init();
registerNativeCallback();



}


void Test::init()
{
uTest_ = new UnmanagedTest();

testDelegate_ = gcnew TestDelegate( this, &Test::TestCallback );
testHandle_ = GCHandle::Alloc( testDelegate_,
GCHandle::Normal );



}


void Test::registerNativeCallback()
{
IntPtr ip =
Marshall::GetFunctionPointerForDelegate( testDelegate_ );
uTest_->RegisterCallback( static_cast< void(__stdcall *)(int)

( ip.ToPointer() ) );
}


void Test::TestCallback(Int32 pointlessParam)
{


}


******************************

The unmanged class UnmanagedTest is just a native class that has a
function pointer variable that is set by the call to
RegisterCallback.


My question is this, I need to do the exact same thing that I'm doing
here, but with an interface.


Is this possible? And if it is, can you please either show me how or
point me in the right direction?


Thank you in advance,


Matthew
 
E

Erik Wikström

Hi,


I'm writing an application that has a native c++ layer, and a CLi/C++
layer above it. Above the CLi layer will be C# but that's not
relavent to this post. My question has to do with communicating
between the native layer to the CLi layer. Typically how I do this
is
this ...

Sorry, wrong group. Marshalling between managed and unmanaged code
should be discussed in a .Net group, or at the very least a group
discussing C++/CLI. Check the microsoft.public.* hierarchy or try
forums.msdn.microsoft.com.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top