2010-11-22 30 views
0

我嘗試調用的DllImport以下艾莎函數(從documentation時:P /調用EntryPointNotFoundException試圖分配指針容器

#define snd_seq_client_info_alloca(ptr) __snd_alloca(ptr, snd_seq_client_info) 

上堆分配snd_seq_client_info_t 容器

下面是我在C++中發現的一個實現,它是在閱讀類似於我想要在Mono中完成的application的代碼時:

snd_seq_client_info_t* cinfo; 
snd_seq_client_info_alloca(&cinfo); 

這裏就是我有這麼遠,但它不工作:

[DllImport(libasound.so.2)] 
private static extern void snd_seq_client_info_alloca(out IntPtr ptr); 

internal static void MyFunction() 
{ 
    IntPtr clientInfo = IntPtr.Zero; 
    snd_seq_client_info_alloca(out clientInfo); 
    // and then some more ... 
} 

,但我得到以下異常:

System.EntryPointNotFoundException: snd_seq_client_info_alloca 
at (wrapper managed-to-native) 
MonoMultiJack.ConnectionWrapper.Alsa.LibAsoundWrapper:snd_seq_client_info_alloca (intptr&) 

回答

3

snd_seq_client_info_alloca是一個預處理器宏。您不能P /調用預處理器宏,只能正確導出函數。

snd_seq_client_info_alloca擴展爲__snd_alloca這也是一個預處理宏。

__snd_alloca本質上擴展到致電alloca。你可以嘗試在C#中重寫。但是我認爲,如果調用者是託管代碼,那麼在調用者的堆棧幀中分配內存沒有多大意義。

只在其他地方分配一些內存(例如,使用Marshal.AllocHGlobal)。

+0

`EntryPointNotFoundException`和`#define`。噢,有時候只是忽略了那些顯而易見的東西。謝謝。至少它現在編譯,我只需要搜索庫代碼來分配內存大小。 – Residuum 2010-11-23 11:55:26