Game Development Reference
In-Depth Information
for (int blockIndex = 0; blockIndex < countDiv; blockIndex++)
{
*((int*)destinationByte) = *((int*)sourceByte);
destinationByte++;
sourceByte++;
}
for (int blockIndex = 0; blockIndex < countMod; blockIndex++)
{
*destinationByte = *sourceByte;
destinationByte++;
sourceByte++;
}
}
}
}
Example: Win32 API Access
The following example shows how to interact with Win32 API calls through
PInvoke and unsafe pointers. There are alternatives to this approach, but this exam-
ple shows how to do it with unsafe code. This example retrieves the name of the
local machine.
[System.Runtime.InteropServices.DllImport(“Kernel32”)]
static extern unsafe bool GetComputerName(byte* lpBuffer, long* nSize);
private static void Win32APIAccess()
{
byte[] buffer = new byte[512];
long size = buffer.Length;
unsafe
{
long* sizePtr = &size;
fixed (byte* bufferPtr = buffer)
{
GetComputerName(bufferPtr, sizePtr);
}
}
Search Nedrilad ::




Custom Search