the calling convention

Jedhi

Well-known member
Joined
Oct 2, 2003
Messages
127
Cclass::Function(BYTE id, void (__cdecl *Func)(BYTE))
{}


The above is written in c how would you write it in C# ?
 
You dont need to worry about calling conventions in C#, since you cant export functions like that. However, you will need to learn how to use delegates.

You need to create a delegate called func, which accepts one byte parameter (to match your Func typedef):
C#:
public delegate void Func(byte b);
This is sort of a prototype for a function. You then need to place it in your functions parameter signature:
C#:
public myFunction(byte id, Func f) {
  // code here
}
You then have to create a function which matches the signature of the Func delegate, and pass that to your function. So:
C#:
public delegateFunction(byte b) { // matches Funcs signature
  // do stuff with [b]b[/b] here
}
And when you call your first function:
C#:
myFunction(42, new Func(delegateFunction));
This is probably very confusing for you, but if you look up delegates in the MSDN, youll find tons of information. :)

Good luck.
 
I will try it out. I was reading a bit about delegates. And it was written that it was preferable to make interfaces instead of delegates because of the type safety. What do you think about it ?
 
Interfaces are different. They are basically prototypes for entire classes. Theres no real way that you could substitute and interface in this case.
 
Back
Top