11

I have a library in C-language. is it possible to use it in C sharp.

http://zbar.sourceforge.net/ is the link of library i want to use

1
  • 1
    definitely not related to WPF. I retag it. Commented Feb 1, 2012 at 9:35

2 Answers 2

18

C Libraries compiled for Windows can be called from C# using Platform Invoke.

From MSDN, the syntax of making a C function call is as follows:

[DllImport("Kernel32.dll", SetLastError=true)]
static extern Boolean Beep(UInt32 frequency, UInt32 duration);

The above calls the function Beep in Kernel32.dll, passing in the arguments frequency and duration. More complex calls are possible passing in structs and pointers to arrays, return values etc...

You will need to ensure that the C functions available by the C library are exported appropriately, e.g. the Beep function is likely declared like this:

#define DllExport   __declspec( dllexport )
DllExport bool Beep(unsigned int frequency, unsigned int duration)
{
    // C Body of Beep function
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Swig to create wrapper for C code in order to use it in c#

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.