0

I use dllimport method (PrintBarcode) in c# on a class library's method().

[DllImport(BXLDIR, SetLastError = true, EntryPoint = "PrinterOpen", CallingConvention = CallingConvention.StdCall)]
public static extern Int32 PrinterOpen(string strPort, Int32 lTimeout);


public static bool PrintOrderNoInfos(string orderNo, string printerIP)
{
      var infos = GetInfosByOrderNo(orderNo).FirstOrDefault();
      var printerOutPortName = String.Format("ETH{0}:9100", printerIP);
      BXLModule.PrinterOpen(printerOutPortName, 1000);
}

Then i reference this class lib dll on presentation layer and when i call this method (PrintOrderNoInfos)

 var res = OrderInfosHelper.PrintOrderNoInfos("2100022127000700", "20.10.15.58");

an error occurs like

A call to PInvoke function 'InfosByOrderNoLibrary!InfosByOrderNoLibrary.BxlPrint::PrinterOpen' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

How can I solve this error?

Thanks in advance.

burakayser
  • 19
  • 2
  • 6
  • The error message tells what you should do: “*Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.”* – Ondrej Tucny Apr 27 '15 at 14:35
  • If you find that [duplicate](http://stackoverflow.com/questions/2941960/a-call-to-pinvoke-function-has-unbalanced-the-stack) did not solve your problem make sure to update the question with results of your investigation so it can be re-opened. Make sure to include signature of native method into the post. – Alexei Levenkov Apr 27 '15 at 14:36
  • Without the declaration of the unmanaged function, nobody can say more than the error message. Who knows, perhaps you got confused between `PrinterOpen` and `PrintBarcode`. – David Heffernan Apr 27 '15 at 14:46

0 Answers0