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

transfer function pointer (fC/C++) to delegate (C#)

Here I am meeting a problem. I am transfering unmanaged C/C++ codes to
managed C# codes. For the general C/C++ function pointer, it is easy to
implement its function by C# delegate. e.g.

Declare (C/C++): double (* f) (double * x, void * parms);
Declare (C#): public delegate double f (double x, object
parms);

And the ways to use them are logically similiar.

My question is: when the function pointer appears in the function
agument list, how to implement this in C#? e.g.

Declare (C/C++): double (* fdf) (double * x, void * parms, double * f,
double * df);

where: f and df are function pointers, say f is declared as the above
instance.

In this situation, how to implement the cooresponding declaration in
C#, or how can I go over it?

thx to all

Nov 24 '05 #1
2 3393
Hi!

I hope I understand your question correctly.
You simply pass a delegate type argument to the method in C#.

So if you have your f delegate:

public delegate double f (double x, object parms);

And you want your fdf method, you would write:

public double fdf ( double x, f ff, f df );

This would take two delegates of type f as parameter. And there is no
reason you could not write:

public delegate double fdfDelegate ( double x, f ff, f df );

Which would be a delegate, that when called, requires two delegate
arguments.

Hope this helps

-Lenard

sg*********@gmail.com wrote:
Here I am meeting a problem. I am transfering unmanaged C/C++ codes to
managed C# codes. For the general C/C++ function pointer, it is easy to
implement its function by C# delegate. e.g.

Declare (C/C++): double (* f) (double * x, void * parms);
Declare (C#): public delegate double f (double x, object
parms);

And the ways to use them are logically similiar.

My question is: when the function pointer appears in the function
agument list, how to implement this in C#? e.g.

Declare (C/C++): double (* fdf) (double * x, void * parms, double * f,
double * df);

where: f and df are function pointers, say f is declared as the above
instance.

In this situation, how to implement the cooresponding declaration in
C#, or how can I go over it?

thx to all

Nov 24 '05 #2
cool Lenard, it make my concept clear! It works and thank a lot.

Nov 24 '05 #3

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

Similar topics

5
by: ZhangZQ | last post by:
if there is a function in a win32 dll, it is definition is int add(int a, int b); how to define that function pointer in C#? thank you very much!
2
by: David Rose | last post by:
I have a DLL (not .NET) that takes a function pointer argument and calls that function with an integer argument. The DLL is being called from C#. So far, it is partially working, but the...
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: Abubakar | last post by:
Hi, I'm making a windows forms app in vs.net 2k3. I added a new "generic c++" (unmanaged class) class to the project which contains some code to access the win32api. Now at a certain point in my...
6
by: Peter Oliphant | last post by:
Here is a simplification of my code. Basically, I have a class (A) that can be constructed using a function pointer to a function that returns a bool with no parameters. I then want to create an...
10
by: ChrisB | last post by:
Coming from a C/C++ background, how would I pass a function pointer to a function? I want to write a function that handles certain thread spawning. Here's what I'm trying to invision: function(...
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...
10
by: vcquestions | last post by:
Hi. Is there way to have a function pointer to a delegate in c++/cli that would allow me to pass delegates with the same signatures as parameters to a method? I'm working with managed code. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.