我尝试在以下Alsa函数上调用DllImport(来自documentation:
#define snd_seq_client_info_alloca( ptr ) __snd_alloca(ptr, snd_seq_client_info)
分配snd_seq_client_info_t 堆栈上的容器
这是我在C ++中找到的实现,同时读取application的代码,类似于我想在Mono中完成的内容:
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&)
答案 0 :(得分:3)
snd_seq_client_info_alloca
是一个预处理器宏。你不能P / Invoke预处理器宏,只能正确导出函数。
snd_seq_client_info_alloca
也扩展为__snd_alloca
,这也是预处理器宏。
__snd_alloca
本质上扩展为对alloca
的调用。您可以尝试在C#中重写它。但是我相信如果调用者是托管代码,在调用者的堆栈帧中分配内存没有多大意义。
只需在其他地方分配一些内存(例如,使用Marshal.AllocHGlobal)。