-
April 19th, 2011, 07:56 AM
#1
Attempted to read or write protected memory.
Dear All,
I have a problem with calling a dll which writed by C++
Code:
private void read_Click(object sender, EventArgs e)
{
if (OpenCom(3) > 0)
MessageBox.Show("COM 3 is opened");
else
MessageBox.Show("Error");
int[] data = new int[128];
string text1 = "";
if (readVW(2, 100, 1, data[0]) > 0)//<-- here is an exception occur,readVW is a method in a dll file,I have used dllimport to import it
{
for (int i = 0; i < 6; i++)
{
text1 = text1 + data[i] + ",";
VWread.Text = text1;
}
}
else
{
text1 = "Error1";
VWread.Text = text1;
}
}
When I run it, an error message"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
What is the problem of it?Thanks
-
April 19th, 2011, 08:04 AM
#2
Re: Attempted to read or write protected memory.
your DllImport declaration is broken. Paste the C function and C# method.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
-
April 22nd, 2011, 12:22 AM
#3
Re: Attempted to read or write protected memory.
That or you've mixed up your calling conventions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|