PInvokeDeclarationsShouldBePortable

FxCop is giving me a PInvokeDeclarationsShouldBePortable error on my use of IntPtr in the following declaration:

<DllImport("shell32.dll", CallingConvention:=CallingConvention.Winapi)> _
Private Shared Function ExtractIcon(ByVal hInst As IntPtr, ByVal lpszExeFileName As String, _
ByVal nIconIndex As IntPtr) As IntPtr
End Function

I did a Google search and found a post where someone said that "Handles, such as hWnds, hIcons, etc should always be declared as IntPtr. It makes the code more portable to say 64-bit when the time comes".

http://www.dotnet247.com/247reference/msgs/28/141400.aspx

So, I'm wondering if this is a false hit on the part of FxCop

Should I change my use of IntPtr? If yes, what should I change it to? I'm using VB.NET 2003 so I can't use unsigned integers.

[1045 byte] By [Anon] at [2008-2-8]
# 1
FxCop isn't flagging your handle usage, it's flagging your use of IntPtr to represent the icon index (which isn't a handle at all):

Resolution : "As it is declared in your code, parameter 'nIconIndex'
of PInvoke test.ExtractIcon(IntPtr, String, IntPtr)
:IntPtr will be 8 bytes wide on 64-bit platforms. This
is not correct, as the actual native declaration of
this API indicates it should be 4 bytes wide on 64-bit
platforms. Consult the MSDN Platform SDK documentation
for help determining what data type should be used
instead of 'System.IntPtr'.
"

According to pinvoke.net, this argument should be a uint, which is legal in vb.net 2003:

<DllImport("shell32.dll", CallingConvention:=CallingConvention.Winapi)> _
Private Shared Function ExtractIcon(ByVal hInst As IntPtr, ByVal lpszExeFileName As String, _
ByVal nIconIndex As UInt32) As IntPtr
End Function

Michael

MichaelFanning-MS at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...

Visual Studio Team System

Site Classified