I have a dll library for which the call in .net is as follows.
It gives me Access Violation Exception. Attended to read or write protected memory. I am new to C# and have been trying to resolve this in the last couple days. Any help will be appreciated.
Code:
Declare Function CopyDesign Lib "OS50.DLL" _
(ByVal I_RPath As String, ByVal I_Flags As Integer, ByVal I_Typ As String, _
ByVal I_CC As Integer, ByVal I_Ref As String, ByVal I_Q As Double, _
ByVal I_T0 As Double, ByVal I_TC As Double, ByVal I_TS As Double, _
ByVal I_TL As Double, ByVal I_TM As Long, ByVal I_TLC As Double, _
ByVal I_TOC As Integer, ByVal I_TOL As Double, ByVal I_TN As Double, _
ByVal I_OP As Integer, ByVal I_SP As Single, ByVal I_CR As Single, _
ByVal O_T1 As String, ByRef O_SzT1 As Integer, _
ByVal O_T2 As String, ByRef O_SzT2 As Integer, _
ByRef DesignData As TDesignData, _
ByRef O_Hint1 As Integer, ByRef O_Hint2 As Integer, _
ByVal O_Err As String, ByRef O_SzErr As Integer) As Integer
I have written the following call, but it won't work.
public struct TDesignData
{
public int O_OP1;
public int O_OP2;
public double O_Q1;
public double O_Q2;
public double O_QU1;
public double O_QU2;
public double O_QN1;
public double O_QN2;
public double O_QC1;
public double O_QC2;
public double O_QH1;
public double O_QH2;
public double O_P1;
public double O_P2;
public double O_E1;
public double O_E2;
public double O_EN1;
public double O_EN2;
public double O_VG1;
public double O_VG2;
public float O_MT1;
public float O_MT2;
public double O_M1;
public double O_M2;
public double O_ME1;
public double O_ME2;
public double O_QS1;
public double O_QS2;
public double O_TE1;
public double O_TE2;
public double O_PE1;
public double O_PE2;
public double O_TL1;
public double O_TL2;
public double O_TH1;
public double O_TH2;
public double O_QA1;
public double O_QA2;
public double O_VOL1;
public double O_VOL2;
public double O_TOL1;
public double O_TOL2;
public double O_TJ1;
public double O_TJ2;
public double O_PJ1;
public double O_PJ2;
}
[DllImport("OS50.DLL",
CallingConvention = CallingConvention.StdCall)]
public static extern int CopyDesign(
string I_RPath,
int I_Flags,
string I_Typ,
int I_CC,
string I_Ref,
double I_Q,
double I_T0,
double I_TC,
double I_TS,
double I_TL,
long I_TM,
double I_TLC,
int I_TOC,
double I_TOL,
double I_TN,
int I_OP,
float I_SP,
float I_CR,
string O_T1,
int O_SzT1,
string O_T2,
int O_SzT2,
TDesignData DesignData,
int O_Hint1,
int O_Hint2,
string O_Err,
int O_SzErr);
public void Run()
{
I_RPath = RefFiles;
I_Flags = (CalcWithIPUnits + BIM_Mode);
I_Flags = (I_Flags + CalcWithSuperheat);
I_Flags = (I_Flags + CalcWithSubcooling);
I_CC = 0;
I_Ref = "R717";
I_TS = 1.8;
I_TL = 0;
I_TM = 0;
I_TLC = 0;
I_TOC = 0;
I_TOL = 175;
I_TN = 0;
I_OP = 1;
I_SP = 3500;
I_CR = 100;
I_Typ="OSNA5351";
I_T0=-30;
I_TC=75;
errorMsgNum = CopyDesign(I_RPath,
I_Flags,
I_Typ,
I_CC,
I_Ref,
I_Q,
I_T0,
I_TC,
I_TS,
I_TL,
I_TM,
I_TLC,
I_TOC,
I_TOL,
I_TN,
I_OP,
I_SP,
I_CR,
O_T1,
O_SzT1,
O_T2,
O_SzT2,
DesignData,
O_Hint1,
O_Hint2,
O_Err,
O_SzErr);
Console.WriteLine(DesignData.O_Q1);
Console.WriteLine(DesignData.O_M1);
Console.WriteLine(DesignData.O_P1);
Console.WriteLine(DesignData.O_VOL1);
Console.WriteLine(DesignData.O_TOL1);