mayuki / MraaSharp

.NET(C#, Mono) binding/wrapper for Intel MRAA library
MIT License
4 stars 2 forks source link

Mraa functions in library not declared as extern #1

Open smuellener opened 8 years ago

smuellener commented 8 years ago

Hello Mayuki

We are very interested in using Mraa from C# and could maybe help to complete your work. The question I have is in your native declaration:

[DllImport("libmraa.so")] public extern static MraaResult mraa_pwm_period_ms(MraaPwmContext dev, int ms);

how does the application know where the function mraa_pwm_period_ms is? The function itself is not declared extern in the library code...

We are running Mraa on a Arm processor.

Thank you Steven

mayuki commented 8 years ago

If methods are declared as native method(extern keyword) in C# code, The execution engine (Mono or .NET CLR) searches native libraries and methods by name at runtime. This mechanism is called "P/Invoke (Platform Invoke)".

So, developers need only to know function name, parameters(mraa_pwm_period_ms(int*, int)) and library name(libmraa.so).