最新消息:20210917 已从crifan.com换到crifan.org

【已解决】error CS0246: The type or namespace name ‘DllImport’ could not be found (are you missing a using directive or an assembly reference?)

C# crifan 6298浏览 0评论

【问题】

C#程序中,有类似这样代码:

// Registers a hot key with Windows.
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);

编译后出错:

D:\xxx\downloadSongtasteMusic\frmDownloadSonstasteMusic.cs(15,10): error CS0246: The type or namespace name ‘DllImport’ could not be found (are you missing a using directive or an assembly reference?)

【解决过程】

1.参照:C# 小结 二,添加了:

using System.Runtime.InteropServices;

然后就解决了。

转载请注明:在路上 » 【已解决】error CS0246: The type or namespace name ‘DllImport’ could not be found (are you missing a using directive or an assembly reference?)

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
99 queries in 0.192 seconds, using 23.42MB memory