New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use C lib in .NET Core 2.0? #756
Comments
or How to complete Inter-Process Communication |
@yizhang82 to point to docs on interop with native binaries and IPC. |
.NET Core supports PInvoke, just like the .NET Framework. Define "static extern" functions with a compatible signature in your C# code. Native function: extern "C" int32_t MyNativeFunction(int32_t x, int32_t y, int32_t z)
{
return x + y + z;
} C#: [DllImport("mysharedobject")]
public static extern int MyNativeFunction(int x, int y, int z); (for example)
There are a variety of ways to do IPC; the same options exist in .NET as in other programming languages. Pipes or Sockets are two main options. |
@mellinoe oh....struct, for example, I define a struct named "struct CameraInfo" in server.h, how can I use it, |
Only serialize to JSON or XML? |
If you want to directly share objects in memory, you need to be very careful about the physical layout of your structures. This means that you should use the appropriate fixed-size types, packing directives, etc. on the native side to ensure that their shape is well-defined and predictable. On the C# side, you need to match the structure shape exactly, using the same-sized shapes, as well as Sharing memory like this is pretty fragile, though. Usually you would want to create a well-defined interface between your managed and native layers, and perform explicit calls between them: C#: [DllImport("mysharedobject")]
public static extern void GetCameraInfo(out CameraInfo cameraInfo); Native: extern "C" void GetCameraInfo(CameraInfo* pCameraInfo) { return whatever; } With the above, you still need to match the shape of the This is all very hand-wavy. This is a broad topic, and there are many approaches that can be taken. Given that you are talking about a "CameraInfo" structure, I'm going to say that you should avoid serializing and deserializing large amounts of state through JSON or XML. |
system: Ubuntu 14.04 x64
I have a Header file(.h) and a share object(.so), how can I use it in my .net core app.
The text was updated successfully, but these errors were encountered: