Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than msvcrt, prefix the name with the module name and a period.
When calling memcmp via pinvoke there is no need to use unsafe code or pinning because the framework will automatically pin the arrays for you.
Sample Code:
Example:
Example 1 (x86 and x64):
//Extension Method example
public static class ByteArrayExtensions
{
[DllImport("msvcrt.dll", CallingConvention=CallingConvention.Cdecl)]
private static extern int memcmp(byte[] b1, byte[] b2, UIntPtr count);
public static bool SequenceEqual(this byte[] b1, byte[] b2)
{
if (b1 == b2) return true; //reference equality check
if (b1 == b2) return true;
return memcmp(b1, b2, new UIntPtr((uint)b1.Length)) == 0;
}
}
Edits:
Example 2 (x64 only):
Added (x86 and x64) signature and example.
Removed SetLastError attribute from bottom 2 signatures as memset does not use this API.
Removed confusing signatures
//http://www.cplusplus.com/reference/clibrary/cstring/memcmp/
unsafe bool CompareByteArray(byte[] b1, byte[] b2)
{
fixed (byte* p1 = b1)
fixed (byte* p2 = b2)
{
return memcmp((void*)p1, (void*)p2, b1.Length) == 0;
}
}
Edits:
Added (x86 and x64) signature and example.
Removed SetLastError attribute from bottom 2 signatures as memset does not use this API.
Click to read this page
6/25/2010 2:17:25 PM - -90.152.60.34
The mechanism provided by the CLR that enables managed code to call static DLL exports.k
10/27/2022 9:24:28 PM - 114.37.143.20
Click to read this page
6/25/2010 2:17:25 PM - -90.152.60.34
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).