473,321 Members | 1,778 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,321 software developers and data experts.

Pointer to callback function from C# to C++

Hi

I'm trying to Pass pointer to a callback function from C# to C++ it's
working ok for a few minuts and then it's stops.

can anyone help with that ?

public class PA_Client

{

private int lHandle;

public delegate int pPAEvent( int lEventCode,int lOperationCode,string
sData);

//PAHandShake

[DllImport(@"\PAApi.dll" ,CallingConvention=CallingConvention.Winapi

,CharSet=CharSet.None, EntryPoint = "PAMultiHandShake")]

private static extern int _PAHandShake(ref int lClientHandle,int
lOperationCode,string sServerAddress,pPAEvent pEventFunc);

//PARequest

[DllImport(@"\PAApi.dll",CallingConvention=CallingC onvention.Winapi

,CharSet=CharSet.None,EntryPoint = "PAMultiRequest")]

private static extern int PARequest(int lClientHandle, int lOperationCode,
string sInputData);

//PAControl

[DllImport(@"\PAApi.dll",CallingConvention=CallingC onvention.Winapi

,CharSet=CharSet.None, EntryPoint = "PAMultiControl")]

private static extern int PAControl(int lClientHandle,string sInputData);

{

public void Run_PA()

{

int Success = _PAHandShake(ref lHandle,1,address, new pPAEvent( Callback));

}

private int Callback(int opCode, int eventCode, string InputData)

{

//Do some thing

}

}
Nov 15 '05 #1
1 4369
I'm trying to Pass pointer to a callback function from C# to C++ it's
working ok for a few minuts and then it's stops.

can anyone help with that ?


You have to keep a reference to the delegate to prevent if from being
garbage colelcted.

http://www.dotnetinterop.com/faq/?q=DelegateGC

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2

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

Similar topics

9
by: Chris Jankowski | last post by:
Hi all, I am still new to using Python, so bare with me. I am trying to call a DLL from my program to use some of it's functions. The only parameter is supposed to be a pointer to an image. I...
1
by: pvdm | last post by:
Hi, I am writing an app which encapsulates a multimedia timer. I implemented a TimerProc as static member function and a static member variable pThis as pseudo this variable to access in the...
2
by: Bj?rn Toft Madsen | last post by:
Hi all, The network library I use communicates with my app using a callback function. This callback function is called with the type of message, a void pointer to he actual message and a user...
15
by: Albert | last post by:
Hi, I need to pass a pointer-to-member-function as a parameter to a function which takes pointer-to-function as an argument. Is there any way to do it besides overloading the function? Here...
6
by: keepyourstupidspam | last post by:
Hi, I want to pass a function pointer that is a class member. This is the fn I want to pass the function pointer into: int Scheduler::Add(const unsigned long timeout, void* pFunction, void*...
1
by: edgekaos | last post by:
I want to pass a structure to a unmanaged dll function. Inside this structure there is a pointer to a callback function. Unmanaged code will call this managed function as a callback function. I...
0
by: Haxan | last post by:
Hi, I have an unmanaged application that converts a function pointer to a delegate and then pass this as a parameter(delegate) to a managed function which then invokes it. Currently Im able to...
1
by: pheres | last post by:
Hi, I'm trying to pass pointers to member functions around in my code. The test with pointers to non-member function works fine: Code: void callOut( void (*callback)() ) { callback();
5
by: Tim Frink | last post by:
Hi, I'm experimenting with function pointers and found two questions. Let's assume this code: 1 #include <iostream> 2 class A; 3 4 //////////////////////////////////////////// 5 class B
7
by: ghulands | last post by:
I am having trouble implementing some function pointer stuff in c++ An object can register itself for many events void addEventListener(CFObject *target, CFEventHandler callback, uint8_t...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.