Native to Manage communication via callback interface

Discussion in 'C++' started by DaTurk, Aug 26, 2008.

  1. DaTurk

    DaTurk Guest

    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
    DaTurk, Aug 26, 2008
    #1
    1. Advertising

  2. On 2008-08-26 21:51, DaTurk wrote:
    > 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.

    --
    Erik Wikström
    Erik Wikström, Aug 26, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SklNLkgu?=

    Q: creating interface to manage patient demographics

    =?Utf-8?B?SklNLkgu?=, Mar 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    358
    =?Utf-8?B?SklNLkgu?=
    Mar 9, 2005
  2. Jéjé
    Replies:
    0
    Views:
    451
    Jéjé
    May 29, 2005
  3. valere
    Replies:
    0
    Views:
    349
    valere
    Apr 2, 2004
  4. Serge Kruppa
    Replies:
    0
    Views:
    236
    Serge Kruppa
    Oct 4, 2006
  5. Wak Karot
    Replies:
    0
    Views:
    226
    Wak Karot
    May 2, 2008
Loading...

Share This Page