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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top