How to resolve the CA1901 - P/Invoke declarations should be portable FxCop warning?

790 Views Asked by At

I was using the SendMessage native method in my sample. Please find the native method declaration below,

[DllImport("user32.dll", CharSet = CharSet.Auto)] 

internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

But when declare the above native method in my sample, it shows the warning(CA1901 - P/Invoke declarations should be portable). It shows the warning like "the parameter lParam in method will be 4 bytes wide on 64-bit platforms. This is not correct, as the actual native declaration of this API indicates it should be 8 bytes wide on 64-bit platforms.

So how we can solve this above FxCop warning, and also please suggest how we can know the actual size of the parameter based on the 32 bit and 64 bit platforms?

1

There are 1 best solutions below

0
On

You should use the following declaration:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);