[英]What is wrong with my INTEROP snippet?
這怎么了 我似乎無法弄清楚如何更改它。 請幫忙....!!!! 這是錯誤消息:對PInvoke函數'MyClassName :: Process'的調用已使堆棧不平衡。 這可能是因為托管PInvoke簽名與非托管目標簽名不匹配。 檢查PInvoke簽名的調用約定和參數是否與目標非托管簽名匹配。
#include "stdafx.h"
#include "TestDll.h"
extern "C" __declspec(dllexport) void Process(lpUnmagedStruct lpStruct, int size)
{
lpStruct[0].a = 0;
lpStruct[0].b = 0;
lpStruct[1].a = 1;
lpStruct[1].b = 1;
}
typedef struct
{
double a;
double b;
}UnmanagedStruct, far *lpUnmagedStruct;
extern "C" __declspec(dllexport) void Process(lpUnmagedStruct lpStruct, int size);
這是我的.NET代碼:
[DllImport("TestDLL.dll", EntryPoint = "Process", CharSet = CharSet.Ansi)]
internal static extern void Process([In, Out] ManagedStruct[] aStruct, int size );
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class ManagedStruct
{
public double a;
public double b;
}
const int size = 3;
ManagedStruct[] aStruct = new ManagedStruct[size];
Process(aStruct, size);
我懷疑您需要添加調用約定:
[DllImport("TestDLL.dll",
EntryPoint = "Process",
CharSet = CharSet.Ansi,
CallingConvention=CallingConvention.Cdecl)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.