1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | /* Platform Invocation Facility Example This code is intended to illustrate P/Invoke. For out purposes we will access a c shared library. */ using System; // This is a lot of the magic! using System.Runtime.InteropServices; /* Class illustrates pinvoking existing c library code */ public class PInvokeExample { /* Notifying the runtime that we need an additional mathematics library, libm.so */ [DllImport("libm")] /* Here we define the external function we will be using from the library, You must declare these methods to be static. The function signature you provide must match the signature in the external library! */ static extern double sqrt ( double element ); public static void Main () { Console.WriteLine("The square root of 100.0 is {0}.", sqrt(100.0)); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |