You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// <summary>/// Write the BcmCanFdMessage to the socket. Variant for 32-bit./// </summary>/// <param name="socketHandle">Socket Handle Wrapper Instance</param>/// <param name="message">BCM Message to write</param>/// <param name="msgSize">Size of BCM Message in bytes</param>/// <returns>The number of bytes written on success, -1 on error</returns>[DllImport("libc",EntryPoint="write",SetLastError=true)]publicstaticexternintWrite(SafeFileDescriptorHandlesocketHandle,BcmCanFdMessage32message,intmsgSize);/// <summary>/// Write the BcmCanSingleMessage to the socket. Variant for 32-bit./// </summary>/// <param name="socketHandle">Socket Handle Wrapper Instance</param>/// <param name="message">Special Single Frame BCM Message to write</param>/// <param name="msgSize">Size of BCM Message in bytes</param>/// <returns>The number of bytes written on success, -1 on error</returns>[DllImport("libc",EntryPoint="write",SetLastError=true)]publicstaticexternintWrite(SafeFileDescriptorHandlesocketHandle,BcmCanSingleMessage32message,intmsgSize);
They actually are the same native api:
ssize_twrite(intfd, constvoid*buf, size_tcount);
I mean, maybe there is a better way to unify them?
The text was updated successfully, but these errors were encountered:
Your observation is 100% correct. The reason why I provide so many overloads is to allow the .NET marshaller to do most of the heavy lifting for us.
In most cases, it was/is indeed possible to provide a single P/Invoke method signature per native function which takes a generic IntPtr parameter, but then we would need to call Marshal.AllocHGlobal(), Marshal.StructureToPtr() and Marshal.FreeHGlobal() many times over and over again. While it is more code regarding P/Invokes method signatures, it is less code everywhere else. In addition, using the Marshal methods incorrectly can lead to memory leaks and so the less of that we have the safer our code will be.
The api in the class
LibcNativeMethods
such as:They actually are the same native api:
I mean, maybe there is a better way to unify them?
The text was updated successfully, but these errors were encountered: