Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Delphi7 DLL from C#
    text
    copied!<p>I am facing a problem calling a Delphi 7 DLL file from C#. I am new to C# and don't know Delphi that much and I don't need to really knows that much. I just need to get this problem solved as soon as possible.</p> <p>I am trying to call the dll from C# but I get this error : "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."</p> <p>And I have no clue why it is happening . As you will see in my Delphi code , I'm not trying to return any value . I just need to send some commands on the COM port. Please if anyone can help me out of here :(</p> <p><strong>Delphi DLL code:</strong></p> <pre><code>library Project2; uses SysUtils, ComPort, Classes; var com1:TComport ; {$R *.res} procedure moveforward; export; begin com1.WriteAnsiString('#20 P1528 CR'+sLineBreak); com1.WriteAnsiString('#7 P1465 CR'+sLineBreak); end; procedure movebackward; export; begin comport1.WriteAnsiString('#7 P1528 CR'+sLineBreak); comport1.WriteAnsiString('#20 P1465 CR'+sLineBreak); end; procedure stopmove;export; begin comport1.WriteAnsiString('#20 P1500 CR'+sLineBreak); comport1.WriteAnsiString('#7 P1500 CR'+sLineBreak); end; procedure catch; export; begin comport1.WriteAnsiString('#2 P2120 T2000 CR'+sLineBreak); //arm comport1.WriteAnsiString('#30 P2260 T500 CR'+sLineBreak); //gripper end; procedure initialize; export; begin comport1.WriteAnsiString('#2 P2184 T1000 CR'+sLineBreak); //arm comport1.WriteAnsiString('#30 P1980 T2000 CR'+sLineBreak); //gripper end; exports moveforward, movebackward, stopmove, catch, initialize; begin end. </code></pre> <p><strong>C# Code</strong></p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication3 { public partial class Form1 : Form { [System.Runtime.InteropServices.DllImport("Project2.dll")] public static extern void moveforward(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { moveforward(); } } } </code></pre> <p>Any help will be truly appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload