Using PInvoke in C# with function pointer and delegate -
i'm new in c#.
i have c file (and im using make dll file) :
extern "c" { typedef int (__stdcall * t_fun)(int); __declspec(dllexport) int __stdcall executec(int n, t_fun f) { return f(n); } }
then want use in c# code using pinvoke.
public delegate int f_delegate(int n); [dllimport("executec.dll")] public static extern int executec(int n, f_delegate func); public static int funcs(int n){ return n; } static void main(string[] args) { int x = executec(13, funcs); system.console.writeline(x.tostring()); }
and when start program ends immediatly. problem here?
the code in question fine. can verify pasting brand new projects , discovering works well.
the plausible explanations can see are:
- the program runs correctly , ends after starts because expected behaviour. after program prints single value , terminates.
- your code in fact different presented in question.
Comments
Post a Comment