How can I solve this problem? "P / Invoke Ads Must Be Portable"?

This code:

[DllImport("shell32", CharSet=CharSet.Unicode)]
private static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbFileInfo, uint flags);

Causes the following code analysis problem:

CA1901 P / Invoke Declarations Must Be Portable

As indicated in your code, the return type of P / Invoke 'IconUtil.SHGetFileInfo (string, uint, out IconUtil.SHFILEINFO, uint, uint) will be 4 bytes wide on 64-bit platforms. This is not true, since the actual internal declaration of this API indicates that it should be 8 bytes on 64-bit platforms. Refer to the Platform Platform SDK documentation for help determining which data type to use instead of 'int'.

What should I do? I tried MSDN Consulting, but I'm not quite sure what the problem even means.


I also get this for the same line:

CA1060 P/ NativeMethods

P/Invoke, 'IconUtil.SHGetFileInfo(string, uint, out IconUtil.SHFILEINFO, uint, uint) ' NativeMethods, SafeNativeMethods UnsafeNativeMethods.

+3
2

MSDN, , - SHGetFileInfo. :

DWORD_PTR SHGetFileInfo(
  __in     LPCTSTR pszPath,
  DWORD dwFileAttributes,
  __inout  SHFILEINFO *psfi,
  UINT cbFileInfo,
  UINT uFlags
);

, , DWORD_PTR . , UIntPtr.

, , , SHFILEINFO __inout. , ref.

, p/invoke :

[DllImport("shell32", CharSet=CharSet.Unicode)]
private static extern UIntPtr SHGetFileInfo(
    string pszPath, 
    uint dwFileAttributes, 
    ref SHFILEINFO psfi, 
    uint cbFileInfo, 
    uint flags
);

. p/invoke NativeMethods.

+4

, int IntPtr.

0

All Articles