[DllImport("dcrf32.dll")]
public static extern int dc_init(Int16 port, long baud); //初始化
WinAPI的long类型是32位的,而C#的long是64位的,会引发PInvokeStackImbalance错误。
因此需要将原来的long类型改为int类型,C#中int是32位的:
[DllImport("dcrf32.dll")]
public static extern int dc_init(Int16 port, int baud); //初始化
本文介绍了在使用PInvoke调用WinAPI时遇到的堆栈不对称错误,由于C#的long类型与WinAPI中的long类型位数不同,导致该问题。解决方案是将C#中的long类型替换为int类型,以保持堆栈平衡。
3791

被折叠的 条评论
为什么被折叠?



