call c function

  • Thread starter Thread starter James Ou
  • Start date Start date
J

James Ou

hi,everybody,

I create a C# windows application. Can I call a C function
in the application?

Thanks
 
Hi James,

Yes, you can do that through P/Invoke (at least if the C function follows
the WINAPI calling convention, not so sure about __cdecl one). Declare a
"prototype" for a function in C# as

public static extern Foo(...)

and apply DllImportAttribute to that declaration. You might also need to
fine-tune passing certain parameters by applying the MarshalAs attribute to
them.
 
Back
Top