473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

(cont'd) Callback interface to communicate from native C++ -> CLi\C++Options

Sorry, some how I clicked post before I finished.

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
Aug 26 '08 #1
1 1566

"DaTurk" <mm******@hotmail.comha scritto nel messaggio
news:9a**********************************@8g2000hs e.googlegroups.com...
**CLi/C++ Layer**

public ref class Test
{
private:
[...]
UnmanagedTest* uTest_;
[...]
******************************

--MTest.cpp
[...]
void Test::init()
{
uTest_ = new UnmanagedTest();
[...]
The unmanged class UnmanagedTest is just a native class
I think that you should use the IDispose pattern for that class.
In fact, you create an instance of the *unmanaged* class UnmanagedTest() -
using C++ 'new' - but this instance must be freed properly (else you can
have leaks).

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

What should be defined as an interface?
What should this interface seem like? What should be the purpose of this
interface?

Thanks,
Giovanni
Aug 26 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Philippe C. Martin | last post by:
Hi, I am looking for the pros and cons as to how to integrate a Python module into a Windows native application. So far I have looked at 1) coding the C wrapper myself 2) using Pyrex 3)...
8
by: Ash | last post by:
Hello all, I am hoping this is the appropriate newsgroup for a C++ interface design question. I am trying to design an interface for a subscriber to register/deregister handlers for various...
11
by: ajay.sonawane | last post by:
Hello ther I read somewhere that callback function should be global or static member function. 1: I could use static member functions but how could I access members of class which ar not static....
12
by: Mural Kumar via .NET 247 | last post by:
(Type your message here) -------------------------------- From: Mural Kumar Which is the best way to make a remoting server? 1)As a Windows service 2)As a simple exe, which will run in a...
8
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the...
3
by: Martin | last post by:
Hi, I have an aspx page with two dropdownlist controls. I update the options in the second ddl based on selection made in the first. I do this with the ICallbackEventHandler interface, as per...
7
by: Kirk McDonald | last post by:
Let's say I have a function that takes a callback function as a parameter, and uses it to describe an iteration: def func(callback): for i in : callback(i) For the sake of argument, assume...
3
by: Steven W. Orr | last post by:
I decided I could be more articulate. I hope this helps. I'm writing a program that needs to process options. Due to the nature of the program with its large number of commandline options, I...
7
by: DaTurk | last post by:
Hi, I'm coding up an application that has a native c++ layer, asynchronously calling callback in a CLI layer. We originally did this with static inline methods in the CLI layer, but this...
6
by: psbasha | last post by:
Hi , Currenty I am storing the Graphical User Interface options in a string memeber variable of a class as show below: SampleCode Tkinter Modules ( Graphical User Interface):...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.