none
How do I import User32.dll? RRS feed

  • Question

  • I try to import User32.dll but it fails when I try do add it as a reference in Visual Studio 2008. It tells me to check if the dll is accessible or a valid component or assembly.

    How can I add it so I can get the line
    [DllImport("user32.dll")]
    to work?
    Sunday, November 22, 2009 5:58 PM

Answers

  • Hi,

    Could you try

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    
    //or
    
    add using System.Runtime.InteropServices; at the top of your class.
    • Proposed as answer by A.m.a.L Hashim Sunday, November 22, 2009 6:25 PM
    • Marked as answer by liurong luo Monday, November 23, 2009 8:18 AM
    Sunday, November 22, 2009 6:06 PM
  • 1. right-click the "project" icon in solution explorer

    2. click "Add" -> "Existing Item"

    3. browse and select the dll (you will have to change the "file type" combo-box to be able to see it)

    4. click the dll in solution explorer

    5. in the properties pane change the "Copy to Output Directory" property to "Copy if newer" - to make sure the dll is copied to the debug/release directory upon compilation.

    6. to access methods on the dll - you will have to use something like [DllImport("User32.dll" )]
    Thanks,
    A.m.a.L
    Dot Net Goodies
    Don't hate the hacker, hate the code
    • Proposed as answer by A.m.a.L Hashim Sunday, November 22, 2009 6:25 PM
    • Marked as answer by liurong luo Monday, November 23, 2009 8:20 AM
    Sunday, November 22, 2009 6:14 PM

All replies

  • Hi,

    Could you try

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    
    //or
    
    add using System.Runtime.InteropServices; at the top of your class.
    • Proposed as answer by A.m.a.L Hashim Sunday, November 22, 2009 6:25 PM
    • Marked as answer by liurong luo Monday, November 23, 2009 8:18 AM
    Sunday, November 22, 2009 6:06 PM
  • 1. right-click the "project" icon in solution explorer

    2. click "Add" -> "Existing Item"

    3. browse and select the dll (you will have to change the "file type" combo-box to be able to see it)

    4. click the dll in solution explorer

    5. in the properties pane change the "Copy to Output Directory" property to "Copy if newer" - to make sure the dll is copied to the debug/release directory upon compilation.

    6. to access methods on the dll - you will have to use something like [DllImport("User32.dll" )]
    Thanks,
    A.m.a.L
    Dot Net Goodies
    Don't hate the hacker, hate the code
    • Proposed as answer by A.m.a.L Hashim Sunday, November 22, 2009 6:25 PM
    • Marked as answer by liurong luo Monday, November 23, 2009 8:20 AM
    Sunday, November 22, 2009 6:14 PM
  • Thanks all!
    Sunday, November 22, 2009 6:17 PM
  • You can find most signatures you'd mostlikely run into on the pinvoke.net site.
    Sunday, November 22, 2009 7:12 PM