none
p invoke warning dll import RRS feed

  • Question

  • Hi,

     

    I found some code to add a menu item to the system menu. It works fine but when i run code analysis i get a warning on the next line:

    private static extern int AppendMenu(int hMenu, int Flagsw, int IDNewItem, string lpNewItem);


    warning:

    Severity Code Description Project File Line Suppression State
    Warning CA1901 As it is declared in your code, parameter 'IDNewItem' of P/Invoke 'NativeMethods.AppendMenu(int, int, uint, string)' 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. Consult the MSDN Platform SDK documentation for help determining what data type should be used instead of 'uint'. LeegFrameWork c:\Data\Programma\Development\LeegFrameWork_0080\LeegFrameWork\FormMain.cs 1054 Active

    I tried this (but does not work):

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

    private static extern int AppendMenu(int hMenu, int Flagsw, uint IDNewItem, string lpNewItem);  //change int to uint

    What can i do to prevent this warning?


    • Edited by HansvB69 Friday, March 22, 2019 7:53 PM
    Friday, March 22, 2019 7:52 PM

Answers

  • Try this:

    … AppendMenu(IntPtr hMenu, int Flagsw, UIntPtr IDNewItem, string lpNewItem)

    If the warning disappears, this change requires corresponding adjustments in other places.


    • Edited by Viorel_MVP Friday, March 22, 2019 8:53 PM
    • Marked as answer by HansvB69 Saturday, March 23, 2019 5:19 PM
    Friday, March 22, 2019 8:52 PM

All replies

  • Try this:

    … AppendMenu(IntPtr hMenu, int Flagsw, UIntPtr IDNewItem, string lpNewItem)

    If the warning disappears, this change requires corresponding adjustments in other places.


    • Edited by Viorel_MVP Friday, March 22, 2019 8:53 PM
    • Marked as answer by HansvB69 Saturday, March 23, 2019 5:19 PM
    Friday, March 22, 2019 8:52 PM
  • Thanks, it works now. 

    Saturday, March 23, 2019 5:19 PM