2012-02-01 51 views

回答

13

C函數庫庫的鏈接可以從C#中使用Platform Invoke調用。

MSDN,使得C函數調用的語法如下:上述

[DllImport("Kernel32.dll", SetLastError=true)] 
static extern Boolean Beep(UInt32 frequency, UInt32 duration); 

調用Kernel32.dll中的功能蜂鳴,傳遞的參數的頻率和持續時間。更復雜的調用可能會傳入結構和指向數組的指針,返回值等等。

您需要確保C庫可用的C函數爲exported appropriately,例如,嗶聲功能可能是這樣聲明的:

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