PInvokeStackImbalance error

By Adam Nagy

I'm trying to P/Invoke acedPostCommand() so that I could use it to cancel the current command, but I get a PInvokeStackImbalance error when calling acedPostCommand inside my .NET code:

Pinvokestack

How could I solve this?

Here is the P/Invoke I'm using:

[DllImport("acad.exe",
  CharSet = CharSet.Unicode,
  EntryPoint = "?acedPostCommand@@YAHPB_W@Z")]
public static extern bool acedPostCommand(string cmd);

Solution

You also need to specify the calling convention. Once that's done acedPostCommand() works fine:

[DllImport("acad.exe",
  CharSet = CharSet.Unicode,
  CallingConvention = CallingConvention.Cdecl,
  EntryPoint = "?acedPostCommand@@YAHPB_W@Z")]
public static extern bool acedPostCommand(string cmd);

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading