Hi, this is the problem i am having:
I have a PC104 with a ADO card. API's are provided to control ADO card, API is a C Compiled DLL. The example code that shows how to use this API is in C++ and as a initial test i want to port some basic fuctions to C#.
This is whats happening:
C++ Code:
This is the C# code i wrote:Code:void main(void) { char szBuf[512]; if (!OpenBoard6430(BOARD_NO,0x6430,szBuf, &boardconfig)) { cprintf("\n%s",szBuf); cprintf("\nIf an other DM6430 application is running," " please close it and try again."); getch(); return; } DEVICE_NO = boardconfig.device_no; //This is the method signature in the H file: dllExport BOOL OpenBoard6430(int num, int device_id, LPSTR szBuf, BoardConfig *boardconfig ); //BoardConfig is a simple struct with 2 members. }
When i click the button, i get a trying to write to protected memory exception.Code:public char[] szBuf = new char[512]; public struct BoardConfig { int device_no; int it_no; } BoardConfig board; [DllImport("drvr6430.dll")] public static extern bool OpenBoard6430(int num, int id, char[] szBuf, BoardConfig board); private void button1_Click(object sender, EventArgs e) { if (!OpenBoard6430(1, 0x6430, szBuf, board)) { // } else { // } }
What am i doing wrong?
Any help will be GREATLY appreciated.
Thanks




Reply With Quote