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

Callback Functions

I'm having a lot of difficulty getting even the simplest
callback function (void return, no arguments) to work,
from a dll to C#.
When the callback is invoked from the dll, I get a fatal
error, that shuts down the app.
I suspect that the function pointer is passed incorrectly.
I've studied the documentation, and I seem to have things
configured properly.
Are there any bugs that I need to know of, or any hints,
other than what I've found in the documentation?
Thank in advance,

Dennis
Nov 16 '05 #1
6 2220
When the callback is invoked from the dll, I get a fatal
error, that shuts down the app.


So you're passing out the delegate to unmanaged code?

Can you post some code?

Mattias

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

"db_from_mn" <db****@rtessentials.com> wrote in message
news:01****************************@phx.gbl...
I'm having a lot of difficulty getting even the simplest
callback function (void return, no arguments) to work,
from a dll to C#.
When the callback is invoked from the dll, I get a fatal
error, that shuts down the app.
I suspect that the function pointer is passed incorrectly.
I've studied the documentation, and I seem to have things
configured properly.
Are there any bugs that I need to know of, or any hints,
other than what I've found in the documentation?
Thank in advance,

Dennis


It would help if we could see some code or some snippet that is causing the
error
Nov 16 '05 #3
Here is some code, to illustrate my implementation:

In the dll:
typedef void (CALLBACK * UCANEVENT_CALLBACK)( void );
A function to pass the callback function:
UCAN_API eUCANERROR_T eUCanOpenDriver( UCANEVENT_CALLBACK
lpEventCallbackFn );
Where...
UCAN_API is defined as: extern "C" __declspec(dllexport)
eUCANERROR_T is an enumeration.

In the C# code:
public delegate void UCanEventCallbackDelegate( );
[DllImport("UCanApi.dll")]
public static extern eUCANERROR eUCanOpenDriver(
UCanEventCallbackDelegate lpEventCallbackFn);
(This is defined as a member function of the class
CUCanApi)

UCanEventCallbackDelegate MyUCanEventCallback =
new UCanEventCallbackDelegate( UCanEventCallback );
eError = CUCanApi.eUCanOpenDriver( MyUCanEventCallback );

// Callback implementation
void UCanEventCallback( )
{
....
}



-----Original Message-----
When the callback is invoked from the dll, I get a fatal error, that shuts down the app.
So you're passing out the delegate to unmanaged code?

Can you post some code?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ |

http://www.dotnetinterop.comPlease reply only to the newsgroup.
.

Nov 16 '05 #4
Hello Jock,
See my reply to Mattias.
Thanks for the attention.
Dennis
-----Original Message-----

"db_from_mn" <db****@rtessentials.com> wrote in message
news:01****************************@phx.gbl...
I'm having a lot of difficulty getting even the simplest callback function (void return, no arguments) to work,
from a dll to C#.
When the callback is invoked from the dll, I get a fatal error, that shuts down the app.
I suspect that the function pointer is passed incorrectly. I've studied the documentation, and I seem to have things configured properly.
Are there any bugs that I need to know of, or any hints, other than what I've found in the documentation?
Thank in advance,

Dennis
It would help if we could see some code or some snippet

that is causing theerror
.

Nov 16 '05 #5
I solved this problem.
I had not created the delegate instance at the class
level, but in the constructor. It was therefore being
claimed by the garbage-collector.
Thanks for your attention.
Dennis
-----Original Message-----

"db_from_mn" <db****@rtessentials.com> wrote in message
news:01****************************@phx.gbl...
I'm having a lot of difficulty getting even the simplest callback function (void return, no arguments) to work,
from a dll to C#.
When the callback is invoked from the dll, I get a fatal error, that shuts down the app.
I suspect that the function pointer is passed incorrectly. I've studied the documentation, and I seem to have things configured properly.
Are there any bugs that I need to know of, or any hints, other than what I've found in the documentation?
Thank in advance,

Dennis
It would help if we could see some code or some snippet

that is causing theerror
.

Nov 16 '05 #6
Hello Mattias,
I solved this problem.
I had not created the delegate instance at the class
level, but in the constructor. It was therefore being
claimed by the garbage-collector.
Thanks for your attention.
Dennis
-----Original Message-----
When the callback is invoked from the dll, I get a fatal error, that shuts down the app.
So you're passing out the delegate to unmanaged code?

Can you post some code?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ |

http://www.dotnetinterop.comPlease reply only to the newsgroup.
.

Nov 16 '05 #7

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

Similar topics

6
by: Eric Entressangle | last post by:
Hi all, is there any trouble setting an C++ static class method as callback function for a C program or library ? Thanks
5
by: Pratik | last post by:
what are callback functions? Where we require callback functions? In what scenario we require callback functions?
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....
15
by: Felix Kater | last post by:
Hi, in a given library I register callback functions with this function: bool set_callback(int index, int (*callback_function)(long)); I need the callback function to also pass the index...
4
by: Jimmy | last post by:
I need to use Asynchronous Socket functions in a server application and am learning from sources such as the MSDN2 (http://msdn2.microsoft.com/en-us/library/bbx2eya8.aspx). What I observed is that...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
2
by: Evan Burkitt | last post by:
Hi, all. I have a Windows DLL that exports a number of functions. These functions expect to receive a pointer to a callback function and an opaque void* parameter. The callback functions are...
1
by: kikivenkat | last post by:
Hi, I understand the concept of function pointers. I am a little confused with the call back functions. 1.If a function is invoked using a function pointer, then does it mean the function...
5
by: Jef Driesen | last post by:
I have a C DLL that I want to use from a C# project. The C header file contains these declarations: typedef void (*callback_t) (const unsigned char *data, unsigned int size, void *userdata);...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
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...

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.