我正在尝试从 GitHub 的 CMark 分支 PInvoke 以下函数
char *cmark_markdown_to_html(const char *text, size_t len, int options)
这是我的 PInvoke 签名:
[DllImport("cmark.dll")]
public static extern IntPtr cmark_markdown_to_html(
[In()] [MarshalAs(UnmanagedType.LPStr)] string text,
[MarshalAs(UnmanagedType.SysUInt)] uint len,
[MarshalAs(UnmanagedType.SysInt)] int options);
我这样称呼它:
var retValue = cmark_markdown_to_html(markdown, 0, 0);
但是,它会抛出一个 Marshaling 异常,并带有以下消息:
Cannot marshal 'parameter #2':
Invalid managed/unmanaged type combination
(Int32/UInt32 must be paired with I4, U4, or Error).
好的,所以我将签名更改为:
[DllImport("cmark.dll")]
public static extern IntPtr cmark_markdown_to_html(
[In, MarshalAs(UnmanagedType.LPStr)] string text,
[MarshalAs(UnmanagedType.U4)] uint len,
[MarshalAs(UnmanagedType.I4)] int options);
现在它抛出一个PInvokeStackImbalance
错误
The name '$exception' does not exist in the current context
本土的东西对我来说是个谜。有人可以帮忙吗?