Jedhi Posted October 6, 2003 Posted October 6, 2003 Cclass::Function(BYTE id, void (__cdecl *Func)(BYTE)) {} The above is written in c how would you write it in C# ? Quote
*Experts* Volte Posted October 6, 2003 *Experts* Posted October 6, 2003 You don't need to worry about calling conventions in C#, since you can't 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): public delegate void Func(byte b);This is sort of a prototype for a function. You then need to place it in your function's parameter signature: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:public delegateFunction(byte b) { // matches Func's signature // do stuff with [b]b[/b] here }And when you call your first function:myFunction(42, new Func(delegateFunction));This is probably very confusing for you, but if you look up delegates in the MSDN, you'll find tons of information. :) Good luck. Quote
Jedhi Posted October 6, 2003 Author Posted October 6, 2003 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 ? Quote
*Experts* Volte Posted October 6, 2003 *Experts* Posted October 6, 2003 Interfaces are different. They are basically prototypes for entire classes. There's no real way that you could substitute and interface in this case. Quote
Jedhi Posted October 8, 2003 Author Posted October 8, 2003 Also in this case ! http://www.xtremedotnettalk.com/showthread.php?s=&threadid=77771 Quote
Jedhi Posted January 8, 2004 Author Posted January 8, 2004 Cclass::Function(BYTE id, void (__cdecl *Func)(BYTE status)) Lets say that status is an event. How would you do it ? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.