473,326 Members | 2,173 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,326 software developers and data experts.

Call backs from C?

I'm calling C functions (in a DLL) using platform invoke. This is NOT a COM
dll.
Is it possible to pass a C# function pointer to C so it can call C#
functions?
Thanks,
Siegfried
Nov 16 '05 #1
1 1295
Hi,

"Siegfried Heintze" <si*******@heintze.com> wrote in message
news:OZ**************@TK2MSFTNGP12.phx.gbl...
I'm calling C functions (in a DLL) using platform invoke. This is NOT a COM dll.
Is it possible to pass a C# function pointer to C so it can call C#
functions?
Yes, create a delegate type for that callback function and use the delegate
inside the function prototype for the callback parameter.

It's also important when you create a delegate instance and pass it to the
unmanaged side that you keep a managed reference to that instance alive.
Don't pass a temporarly delegate instance.

e.g.

public delegate void MyCallBackHandler(int a, int c);

[DllImport(....)] // the delegate marshals to a ftn-ptr.
public extern static SetCallback( MyCallBackHandler callback );

class SomeClass
{
MyCallBackHandler callback;

public void SomeMethod()
{
callback = new MyCallBackHandler( OnCallBack );
SetCallback( callback );
}

private void OnCallBack( int a, int c )
{
//...
}
}
HTH,
greetings
Thanks,
Siegfried

Nov 16 '05 #2

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

Similar topics

6
by: Robin Becker | last post by:
I'm trying to better my understanding of multithreading. I believe a thread that calls an extension must have the GIL. What happens if the extension then calls back into Python? Can a function or...
7
by: VK | last post by:
Hello: Since our application uses ASP, I am posting this in this group. Pardon if wrong group. Our product/application replies a lot on bounced back emails, that way we correct this and let...
0
by: Rosanne | last post by:
I have an aspx page that contains a custom built component. Thi component contains a panel. At runtime text boxes are built and adde to the controls collection of the panel on an as needed basis....
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
0
by: orianavim | last post by:
Hi, I'm using my IIS 6.0 built in SMTP service to send email from my application (C#). However, I need to figure out a way to find which emails are getting bounced. I there any way to intercept...
2
by: hibaru | last post by:
Hi Is it possible to call a javascript function from a treeview controls OnSelectedNodeChanged event? Something similar to a OnClientClick event for buttons? I cant seem to find anyway to do...
0
by: dotnet_nut | last post by:
I need to populate a combo-box based upon the selection from another combo-box without postbacks. I know its possible using asp.net 2.0 client call backs. Any samples in Vb.Net will be helpful. ...
0
by: culubalo | last post by:
Ok so this has been annoying me since yesterday but should be simple enough to do. If I create, say a picture box in an array, in code in Form1.h as follows: System::Windows::Forms::PictureBox^...
0
by: vsrprasad16 | last post by:
Hi All, I am running a background thread and this thread will process a method and then based on result it will load a form with some controls. after work, i need to close the form and also kill the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.