Im trying to call from C# .net 3.5 a old Delphi DLL.
DLL, Syntax (Delphi):
Code:
function WLePesoControlado8540(const Conexao,NLeiturasEstaveis,Timeout: integer; Bruto, Liquido, Tara,Motion,Print,PesoMinimoStick out tongueChar):Integer; stdcall;external 'MGB.DLL';
C# Code:
Code:
[DllImport("MGB.dll", EntryPoint = "WLePesoControlado8540", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
private static extern int WLePesoControlado8540(int conexao, int nleiturasestaveis, int timeout, StringBuilder bruto, StringBuilder liquido, StringBuilder tara, StringBuilder motion, StringBuilder print, string peso_minimo);
........
public bool RecebePeso()
{
string strBruto, strLiquido, strTara, strMotion, strPrint;
string strPesoMin = "-1000";
StringBuilder strbBruto = new StringBuilder(10);
StringBuilder strbLiquido = new StringBuilder(10);
StringBuilder strbTara = new StringBuilder(10);
StringBuilder strbMotion = new StringBuilder(10);
StringBuilder strbPrint = new StringBuilder(10);
iRetorno = WLePesoControlado8540(iConexao, 0, 10, strbBruto, strbLiquido, strbTara, strbMotion, strbPrint, strPesoMin);
strBruto = strbBruto.ToString();
strLiquido = strbLiquido.ToString();
strTara = strbTara.ToString();
strMotion = strbMotion.ToString();
strPrint = strbPrint.ToString();
.............
Exception:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Porter.Balanca.WLePesoControlado8540(Int32 conexao, Int32 nleiturasestaveis, Int32 timeout, StringBuilder& bruto, StringBuilder& liquido, StringBuilder& tara, StringBuilder& motion, StringBuilder& print, String peso_minimo)
at Porter.Balanca.RecebePeso() in C:\Documents and Settings\Sergio\Meus documentos\Visual Studio 2008\Projects\Porter\Porter\Balanca.cs:line 112
at Porter.Porter.tmrPegaPeso_Tick(Object sender, EventArgs e) in C:\Documents and Settings\Sergio\Meus documentos\Visual Studio 2008\Projects\Porter\Porter\Porter.cs:line 75
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndPr oc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Please, Somebody can help me ?