Vikram

Vikram

  • 1.4k
  • 276
  • 308.3k

Calling VC++ DLL Giving System.AccessViolationException

Mar 3 2012 8:11 AM
Hi,

  We are developing one windows application where we are reading Hardware via Serial Port. Now we dont have Hardware so we are using simulator for testing. This simulator working fine with VB Test Application where VB application use one VC++ dll which read data from Simulator.
  We are using same dll in C# windows application. This dll returns actually array of integer. While reading data from we are getting Syste.AccessViolation Exception.

 This is the code which I used. I have decalred this in class. 

To Open TCP Port:

[

static extern long MT_Open_TcpPort(ref long socketHandle, string remoteIP, long remotePort);

[

static extern long MT_Read_Data(long socketHandle, byte devID, int address, int qty, ref int[] hold_reg);

While Reading data:

To Open Port : 

retval = MT_Open_TcpPort(

 To Read Data:

retval = MT_Read_Input_Reg(sockethandle, 1, 100, 3,

For this statement, We are getting System.AccessViolation Exception:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

  Any Help Appreciated.

Regards,

  Vikram Patil



ref hold_reg);
ref sockethandle, "127.0.0.1", 502);
DllImport("MT_TCP_Data_RTU.dll", EntryPoint = "MT_Open_TcpPort")]
DllImport("MT_TCP_Data_ RTU.dll", EntryPoint = "MT_Read_Data")]

Answers (3)