无法将 User32.dll 导入 Visual Studio [英] Can't import User32.dll into Visual Studio

查看:45
本文介绍了无法将 User32.dll 导入 Visual Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过了:

  • 要从 Reference Manager 添加 user32.dll,然后从 Windows\System32\user32.dll 导入,我得到了错误信息:

  • To add user32.dll from Reference Manager, and imported it from Windows\System32\user32.dll, I got Error Message:

无法添加对C:\Windows\System32\user32.dll"的引用.请确保该文件可访问,并且它是有效的程序集或 COM 组件.

使用 System.Runtime.InteropServices;[DllImport("user32")]

以管理员身份启动 Visual Studio

To launch Visual Studio as Administrator

没有任何效果……这让我很紧张,我正试图用 2 个小时来导入这个该死的 .dll ……

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

推荐答案

您不需要添加对 User32.dll 的引用.它是 Windows 的一部分,可以在不添加引用的情况下导入到您的代码中.您可以使用 P/Invoke 执行此操作.

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");
}

另见:

这篇关于无法将 User32.dll 导入 Visual Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆