none
change P/Invoke parameter to 8 bytes wide RRS feed

  • Question

  • Hi,

    Visual Studio gives me this warning: 

    As it is declared in your code, parameter 'wParam' of P/Invoke 'NativeMethods.SendMessage(IntPtr, uint, uint, IntPtr)' 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. 

    Following warning regards this API:

      

    public const uint LVSIL_NORMAL = 0; 

    [DllImport("user32")] 

    private static extern IntPtr SendMessage(IntPtr hWnd, uint msg,uint wParam, IntPtr lParam);


     I use this API for assigning Imagelist to my Listview using another API, as follows:

     IntPtr Large_ImagelList = NativeMethods.SendMessage(this.Handle, NativeMethods.LVM_SETIMAGELIST,

    NativeMethods.LVSIL_NORMAL, NativeMethods.System_ImageList);

    Problem I'm facing is that I cannot change "wParam" to IntPtr as warning indicates, because  NativeMethods.LVSIL_NORMAL is a uint constant, and constants cannot be declared as IntPtr. What should I do to remove this warning ?



    Friday, April 20, 2018 9:18 AM

Answers

  • Solved. This is what I did:

    private static IntPtr LVSIL_NORMAL = new IntPtr(0);  

    [DllImportAttribute("user32.dll")] 

     private static extern int SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); 

    IntPtr Large_ImagelList = (IntPtr)NativeMethods.SendMsgTooltip(this.Handle, NativeMethods.LVM_SETIMAGELIST, NativeMethods.LVS_NOR, NativeMethods.Sistemski_Imagelist);


    • Marked as answer by LuckyLuke82 Friday, April 20, 2018 11:14 AM
    Friday, April 20, 2018 11:00 AM

All replies

  • For 64-bit platforms, maybe you should replace uint with UInt64 or with ulong.

    But it is also possible to make a IntPtr variable from uint. See the constructors of IntPtr.


    • Edited by Viorel_MVP Friday, April 20, 2018 10:20 AM
    Friday, April 20, 2018 10:20 AM
  • Solved. This is what I did:

    private static IntPtr LVSIL_NORMAL = new IntPtr(0);  

    [DllImportAttribute("user32.dll")] 

     private static extern int SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); 

    IntPtr Large_ImagelList = (IntPtr)NativeMethods.SendMsgTooltip(this.Handle, NativeMethods.LVM_SETIMAGELIST, NativeMethods.LVS_NOR, NativeMethods.Sistemski_Imagelist);


    • Marked as answer by LuckyLuke82 Friday, April 20, 2018 11:14 AM
    Friday, April 20, 2018 11:00 AM