The following example demonstrates a violation of this rule.
internal class NativeMethods
{
[DllImport("shell32.dll", CharSet=CharSet.Auto)]
internal static extern IntPtr ExtractIcon(IntPtr hInst,
string lpszExeFileName, IntPtr nIconIndex);
}
In this example, the nIconIndex parameter is declared as a IntPtr, which is 4 bytes wide on a 32-bit platform and 8 bytes wide on a 64-bit platform. In the unmanaged declaration that follows, you can see that nIconIndex is a 4 byte unsigned integer on all platforms.
HICON ExtractIcon(HINSTANCE hInst, LPCTSTR lpszExeFileName,
UINT nIconIndex);
To fix the violation, change the declaration to the following:
internal class NativeMethods{
[DllImport("shell32.dll", CharSet=CharSet.Auto)]
internal static extern IntPtr ExtractIcon(IntPtr hInst,
string lpszExeFileName, uint nIconIndex);
}