I have a C ++ dll that has a function inside. I am trying to call from a C # application.
Here is the code in the C ++ header file
extern "C" _declspec(dllexport) int LabelStoringSSDsim(int devNum, UCHAR serial[40], UCHAR wwn[40],
UCHAR ConfigID[5], UCHAR FrmRev[8], UCHAR DevName[40], int eCode);
Here is the code in the C ++ source file
int LabelStoringSSDsim(int devNum, UCHAR serialLbl[40], UCHAR wwnLbl[40],
UCHAR ConfigID[5], UCHAR FrmRev[8], UCHAR DevName[40], int eCode)
{
string strConfigID="12111";
string strFrmRev="1.25....";
string strDevName="ABC-123.................................";
for (int i=0;i<5;i++)
ConfigID[i] = strConfigID[i];
for (int i=0;i<8;i++)
FrmRev[i] = strFrmRev[i];
for (int i=0;i<40;i++)
DevName[i] = strDevName[i];
return eCode;
}
Here's the corresponding C # code
[DllImport("LabelStoring.dll")]
static extern int LabelStoringSSDsim(
int devNum,
byte[] strserial,
byte[] strwwn,
[In] ref byte[] ConfigID,
[In] ref byte[] FrmRev,
[In] ref byte[] DevName,
int eCode);
int errNum = LabelStoringSSDsim(devNum, bserial, bwwn, ref ConfigID, ref FrmRev, ref DevName, 123123);
So, when I get to the last bit of code, I get "Attempting to read or write protected memory. This often indicates that another memory is damaged." error.
I have no experience in importing DLLs, and I searched many times, but could not find a solution to the problem.
, , . int , . , , . , . , .
.