We help IT Professionals succeed at work.
Get Started

PInvoke .net / C++ dll not working.

Last Modified: 2012-05-09
I have probably the most basic setup possible, need to know why it is not working. A very simple C++ dll with a single method called Toast, one int in, with a return of int.

I also have a C# wrapper class with DLLImport function referencing the same

However when I run the deal, I get a nasty error about an unbalanced stack. Like the signature and return type of the wrapper don't match the DLL. Also if you continue through the exception the result comes back as expected.

Why would I be getting this message since the signations match? (return of int and one int in)

__declspec(dllexport) int Toast(int x)
	return x + 100;

public static class Wrapper
        [DllImport("File.dll", EntryPoint = "?Toast@@YAHH@Z")]
        public static extern Int32 WR_TOAST(Int32 x);


Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE