Hello all
i have been on this one for a long time now, i have a c# winform app that calls an unmanaged 32-bit c++ dll, but anytime i try to call it, the app either crashes or brings an exceptional error
"Attemted to read or write protected memory. This is often an indication that other memory is currupt"
below is my code sample, am i doing something wrong!
Notes:
i have tried changing my platform target to X86
i even tried unchecking "Suppress JIT optimization module load"
but none solved the problem
any help will be greatly appreciated.
What I have tried:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Unit1
{
public partial class TForm1: Form
{
public TForm1()
{
InitializeComponent();
}
private bool rdCard()
{
bool result = false;
int st;
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
st = Units.Unit1.ReadCard(Units.Unit1.flagUSB, Units.Unit1.bufCard);
if (st != 0)
{
MessageBox.Show(("Read Card Failure" + '\n' + (st).ToString() + "the buf: " + Units.Unit1.bufCard), "Note", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error);
return result;
}
if (Units.Unit1.bufCard.Substring(0, 6) != "551501")
{
MessageBox.Show(("No Valid Card On Reader" + '\n' + Units.Unit1.bufCard), "Note", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
return result;
}
else
{
result = true;
Cursor.Current = System.Windows.Forms.Cursors.Default;
return result;
}
}
public void BitBtn3Click(System.Object Sender, System.EventArgs _e1)
{
if (!rdCard())
{
return;
}
edt_CardData.Text = Units.Unit1.bufCard;
MessageBox.Show((("Card ID£º" + Units.Unit1.bufCard.Substring(25, 8))), "Note", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
}
}
}
namespace Unit1.Units
{
public class Unit1
{
public static TForm1 Form1 = null;
public static byte flagUSB = 0;
public static int st = 0;
public static string bufCard;
[DllImport("proRFL.DLL")]
public static extern int ReadCard(byte fUSB, string Buffer);
[DllImport("proRFL.DLL")]
public static extern int CardErase(byte fUSB, int dlsCoID, string cardHexStr);
}
}