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:

  1. the program runs correctly , ends after starts because expected behaviour. after program prints single value , terminates.
  2. your code in fact different presented in question.

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -