简体   繁体   中英

WPF: A call to PInvoke function has unbalanced the stack

I'm encountering this error while using one of method in my .dll reference. When I call MyRef.SetDbaseId method I'm returned to VS with this error. I've tried to add CallingConvention enum parameters, but all of them does not work for me. I've also opened dll in DependencyWalker to check entry point and param ( ulong ), which fits in my app. It's confusing because other methods works fine. Any ideas how to solve this problem?

[DllImport("my.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?setdbaseid@@YGHK@Z")]
public static extern int SetDbaseID(ulong dbase_id);
ulong tmid = ulong.Parse(p_6);
i = MyRef.SetDbaseID(tmid);

The mangled name, ?setdbaseid@@YGHK@Z, demangles to:

 int __stdcall setdbaseid(unsigned long);

Which makes your declaration wrong, an unsigned long in native code is 32-bits. And the calling convention is wrong. Fix:

[DllImport("my.dll", EntryPoint = "?setdbaseid@@YGHK@Z"))]
public static extern int SetDbaseID(uint dbase_id);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM