Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

while debugging i got the error like this Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

This below error code line works for capture screen and do ocr. But dynamically(Means Multiple time capturing window with certain time limits) changing window capture and do ocr is giving error.

C#
private void OCRImplementationall()
        {
            MODI.Document md = new MODI.Document();

            Cursor = Cursors.WaitCursor;
            string Name = AppDomain.CurrentDomain.BaseDirectory + @"PT INFO.JPG";
            try
            {
                int fflag = 0;
                CheckForIllegalCrossThreadCalls = false;
                md.Create(Name);
                md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
                string strText = String.Empty;

                MODI.Image image = (MODI.Image)md.Images[0];
                MODI.Layout layout = image.Layout;
                string[] splvalues = layout.Text.Trim().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                //for (int i = 0; i < layout.Words.Count; i++)
                int i = 0;
                foreach (string val in splvalues)
                {}}
  catch (Exception ex)
            {
               //ExceptionHelper exlne = new ExceptionHelper();

                LogFile(ex.Message, "OCRImplementationall", "PT INFO Image Error", ExceptionHelper.LineNumber(ex), this.FindForm().Name);


                //MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
}


May i know whats the issue i made here in this line
Posted
Updated 31-Jul-13 1:26am
v2

Refer - Attempt to read or write Protected Memory This is often an indicating that other memory is corrupt[^].

The answer holds some explanation about the issue. You can also suppress this Exception.
Take a look, it might help you.
 
Share this answer
 
Comments
visnumca123 31-Jul-13 9:16am    
Hi,

i done below steps

Tools menu ->Options -> Debugging -> General -> Uncheck this option "Suppress JIT optimization on module load"


Still its not working...
Did you see other details about what exactly is the issue and all?
From your desciption, I'd rather suspect that the library is not multithreading-proof. Hence you have to wait for the OCR processing to have finished before you start the next processing. That's a limitation of that library, and your code has to obey to those limitation.
 
Share this answer
 
Comments
visnumca123 1-Aug-13 10:32am    
Hi,
I increased thread.sleep(5000) and i did the below
md.Close(false);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(md);
md = null;
GC.Collect();
GC.WaitForPendingFinalizers();
but still i have the same issue!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900