Attempted to read or write protected memory.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Attempted to read or write protected memory.

  1. #1
    Join Date
    Feb 2004
    Posts
    218

    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

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    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.

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center