470,566 Members | 1,428 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,566 developers. It's quick & easy.

Attempted to read or write protected memory = memory leak?

Hello,
i have a question on my mind.

Iam developing application which uses twain layer to scan images. So far everything worked fine, but today while testing i got Attempted to read or write protected memory error.

Basicly what i do:
- set capabilities via imported dll calls of twain.dll
- call acquire call via imported dll calls of twain.dll

i get back IntPtr on the data from scanner, which i convert to bitmap by creating empty bitmap and filling bitmap with pixel data. Then i flip newly created bitmap.

At last mentioned i get sometimes error "Attempted to read or write protected memory".

Strange is that its not always, sometimes i takes 200 pages sometimes 400 pages to scan. For test purposes i used 50 papers, and for other test 1 page picture in kodak twain simulator. So its obvious that the problem is not caused by picture data. I forgot to say that i did scan 40 - 50 pages at batch a than repeated the batch.

What i dont understand is why is it happening, since memory of the picture is allocated by twain driver and not me. (EDIT: That is true, but bitmap iam creating from the twain data is created by me..)

Is it possible that the data are somehow locked by unmanaged memory manager??
Or its more likely that there is leaking memory and so all the unmanaged memory is somehow corupted?

I started with NETMasters code here: http://www.codeproject.com/kb/dotnet/twaindotnet.aspx. Dll calls where used without changes.

Any suggestions will be appreciated.
May 17 '10 #1
0 1523

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Let_Me_Be | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.