4 ms·
Assuming you mean "foreign function interface", then yes, P/Invoke is supported on .NET Core just as it is in the .NET Framework (the Windows component). We use
by mellinoe 10y ago
Assuming you mean "foreign function interface", then yes, P/Invoke is supported on .NET Core just as it is in the .NET Framework (the Windows component). We use it extensively in the core libraries to access platform functionality.
(I work on the core libraries for .NET)
- merb 10y agooh thanks is there any documentation around that or is it better to look into the source?
- mellinoe 10y agoMost of the documentation/tutorials you find will be perfectly relevant, but they may be Windows-centric based on .NET's history. At a really basic level, you simply declare a "static extern" method with a "DllImport" attribute attached to it. For example, you could call "printf" from libc like so: [DllImport("libc")] public static extern void printf(string message); static void Main() { printf("Hello World"); }
- merb 10y agoWhat happens if the library isn't in LD_LIBRARY_PATH could I specify a path with DllImport?
- mellinoe 10y agoYes, you can specify a relative/absolute path in DllImport if you'd like. Generally it is easier to get consistent behavior if you either: 1) rely on the user to install the binary somewhere and place it on the path, or 2) deploy the native binary along with your application. We generally do 1) in .NET Core, or we rely on components of Windows, for example.
- merb 10y agoThat won't work with Nuance CSDK. It will install the Linux binary to /usr/local/nuance-csdk/bin, /usr/local/nuance-csdk/lib, etc..