Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C代码中的C库_C#_C_Pinvoke - Fatal编程技术网

C# 使用C代码中的C库

C# 使用C代码中的C库,c#,c,pinvoke,C#,C,Pinvoke,我有一个C语言库。是否可以在C夏普中使用它 是我要使用的库的链接C可以使用从C#调用为Windows编译的库 从中,进行C函数调用的语法如下所示: [DllImport("Kernel32.dll", SetLastError=true)] static extern Boolean Beep(UInt32 frequency, UInt32 duration); 上面调用Kernel32.dll中的函数Beep,传入参数frequency和duration。更复杂的调用可能会传入结构和指向数

我有一个C语言库。是否可以在C夏普中使用它


是我要使用的库的链接

C可以使用从C#调用为Windows编译的库

从中,进行C函数调用的语法如下所示:

[DllImport("Kernel32.dll", SetLastError=true)]
static extern Boolean Beep(UInt32 frequency, UInt32 duration);
上面调用Kernel32.dll中的函数Beep,传入参数frequency和duration。更复杂的调用可能会传入结构和指向数组的指针、返回值等

您需要确保C库提供的C函数是,例如,Beep函数可能声明如下:

#define DllExport   __declspec( dllexport )
DllExport bool Beep(unsigned int frequency, unsigned int duration)
{
    // C Body of Beep function
}

绝对与WPF无关。我重新标记它。