jovanMeshkov
jovanMeshkov

Reputation: 797

Can't import User32.dll into Visual Studio

I tried:

Nothing works... it goes on my nerves I am trying 2 hours to import this damn .dll...

Upvotes: 13

Views: 30082

Answers (2)

jrbeverly
jrbeverly

Reputation: 1621

You do not need to add a reference to User32.dll. It is part of Windows and can be imported in your code without adding a reference. You do this using P/Invoke.

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void SetWindowText(int hWnd, String text);

private void button3_Click(object sender, EventArgs e)
{
    IntPtr wHnd = this.Handle;//assuming you are in a C# form application
    SetWindowText(wHnd.ToInt32(), "New Window Title");
}

See Also:

Upvotes: 12

Dax Fohl
Dax Fohl

Reputation: 10781

It's not a .NET dll. You don't "add reference" the same way you do with .NET dlls. Instead you have to add P/Invoke code to your app to invoke the functions you want. Here's a good resource for learning pinvoke: http://pinvoke.net/

Upvotes: 1

Related Questions