我有以下使用 DLLImport 的 C# 代码。
using System;
namespace LvFpga {
class RegTest
{
[DllImport("kernel32")]
public extern static int LoadLibrary(string lpLibFileName);
[DllImport("kernel32")]
public extern static bool FreeLibrary(int hLibModule);
public static bool IsDllRegistered(string DllName)
{
int libId = LoadLibrary(DllName);
if (libId>0) FreeLibrary(libId);
return (libId>0);
}
public static void Main(string[] args)
{
Console.WriteLn(IsDllRegistered("msdia100.dll"));
}
}
}
当我只是跑步时csc CSCODE.cs
我得到了错误。
regtest.cs(7,6): error CS0246: The type or namespace name 'DllImport' could not be found (are you
missing a using directive or an assembly reference?)
regtest.cs(7,6): error CS0246: The type or namespace name 'DllImportAttribute' could not be found
(are you missing a using directive or an assembly reference?)
regtest.cs(9,6): error CS0246: The type or namespace name 'DllImport' could not be found (are you
missing a using directive or an assembly reference?)
regtest.cs(9,6): error CS0246: The type or namespace name 'DllImportAttribute' could not be found
(are you missing a using directive or an assembly reference?)
怎么了?选项中可以添加什么?
你必须有
using System.Runtime.InteropServices;
此外,没有函数“Console.WriteLn”。你需要
Console.WriteLine(IsDllRegistered("msdia100.dll"));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)