473,796 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(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(In t32);

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

UnmanagedTest* uTest_;

void init();
void registerNativeC allback();

void TestCallback(In t32);
public:
Test();
}
}

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

--MTest.cpp

#include "Test.h"

using namespace Test;

Test::Test()
{
init();
registerNativeC allback();
}

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

testDelegate_ = gcnew TestDelegate( this, &Test::TestCall back );
testHandle_ = GCHandle::Alloc ( testDelegate_, GCHandle::Norma l );
}

void Test::registerN ativeCallback()
{
IntPtr ip =
Marshall::GetFu nctionPointerFo rDelegate( testDelegate_ );
uTest_->RegisterCallba ck( static_cast< void(__stdcall *)(int)
>( ip.ToPointer() ) );
}

void Test::TestCallb ack(Int32 pointlessParam)
{
}

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

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

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 1609

"DaTurk" <mm******@hotma il.comha scritto nel messaggio
news:9a******** *************** ***********@8g2 000hse.googlegr oups.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
2247
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) go for pywin32 and COM
8
3774
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 events. The callbacks specified by the subscriber will be called when the events get trigerred in a different thread. Each event has different kinds of data associated with it. To achieve this I have the following: // The following describes the...
11
2475
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. 2: I could use global function but want to access members of class. Let me know the possible solutions. Regards, Ajay Sonawane
12
1553
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 system tray.
8
3519
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 individual swithces do not get passed to option parser.
3
7426
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 "Implementing Client Callbacks Without Postbacks in ASP.NET Web Pages" (http://msdn2.microsoft.com/en-us/library/ms178208.aspx) This works.
7
3598
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 the iteration is something more interesting than this which relies on the callback mechanism. The function is an existing interface, and I cannot change it.
3
1525
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 would like to write a callback to be set inside add_option. Something like this: parser.add_option("-b", action="callback", callback=optionhandlr, dest='b')
7
6438
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 solution only works with singleton objects. So I have to explore other solutions. So beside pinning pointers, I've been looking at GCHandle. I was
6
1915
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): ------------------------------------------------------------- a) File.py class File: def __init__(self):
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.