Visual Basic Development Bookmark and Share   
 Home > Visual Basic Interop and Upgrade > My app with an unmanaged dll throws an AccessViolationException after update Vista sp2
 

My app with an unmanaged dll throws an AccessViolationException after update Vista sp2

Hallo Everybody,

I amtrying to use an old unmanaged dll in my VBE2008 Project. My applicationworks fine on mycomputers (3 Vista sp1 and 2 XP sp3 / all with .net framwork 3.5), but after the sp2 update for2 ofVista machines,it throws often (not every time) an AccessViolationException.The error message is:
"Attempt to read or write protected memory. This is often an indication that other memory is corrupt."

I have checked and found thattheexceptionwas thrown bythedll callingfunction.My code looks like this:

<DllImport("abc.dll", EntryPoint:="abc", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=True, llingConvention:=CallingConvention.StdCall)> _
Private Shared Sub abc(ByVal input as integer)
End Sub

The dll is in the same directory with my app and I have tried with the absolute reference like "c:\abc.dll".
How can i fix it? any idea?

thx.

Lert Pianapitham

Pianapitham  Thursday, November 19, 2009 4:51 PM
Hi Lert,

Commonly Access Violation is raised by following factors:

1. Reading/Writing invalid memory block.
2. Accessing memory that has not been allocated or has been freed already
3. Accessing memory address that is reserved (e.g. kernel use >0x7FFFFFFF)
4. Writing to memory block that is marked as “Read-Only�(immutable strings)
5. Wrapped as NullReferenceException/AccessViolationException in .Net


Could you give us native C++ function definition so that we can confirm that the managed signature is correct? Whether you can run this application in Windows7 or Windows2008 without problems (Because I haven't Vista SP2 computer, I want to know if this question occurs in Windows7 or Windows2008 so that I can reproduce your scenario if you can send me your C++ DLL). Commonly we need to use Debugger to investigate this question. Please have a look at this demo:
http://stackoverflow.com/questions/1331320/using-windbg-to-inspect-method-parameters-in-raw-memory-from-crash-dump

We can directly attach Windbg to break at the Exception to investigate the question.

Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Riquel_Dong  Tuesday, November 24, 2009 3:51 AM
Also ... with the Vista sp1 and XP sp2, itworks every time. Only 2 machineswith Vistasp2have this problem.

thx. again
Lert Pianapitham
Pianapitham  Thursday, November 19, 2009 6:30 PM
Hi Lert,

Commonly Access Violation is raised by following factors:

1. Reading/Writing invalid memory block.
2. Accessing memory that has not been allocated or has been freed already
3. Accessing memory address that is reserved (e.g. kernel use >0x7FFFFFFF)
4. Writing to memory block that is marked as “Read-Only�(immutable strings)
5. Wrapped as NullReferenceException/AccessViolationException in .Net


Could you give us native C++ function definition so that we can confirm that the managed signature is correct? Whether you can run this application in Windows7 or Windows2008 without problems (Because I haven't Vista SP2 computer, I want to know if this question occurs in Windows7 or Windows2008 so that I can reproduce your scenario if you can send me your C++ DLL). Commonly we need to use Debugger to investigate this question. Please have a look at this demo:
http://stackoverflow.com/questions/1331320/using-windbg-to-inspect-method-parameters-in-raw-memory-from-crash-dump

We can directly attach Windbg to break at the Exception to investigate the question.

Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Riquel_Dong  Tuesday, November 24, 2009 3:51 AM
Hi Riquel_Dong,

thank for your answer.

Sorry ... Icannot give you the dll due to the Program's licence.But i thinkyou can have one from internet if you want to do a search.It's name RefProp.dll.

My Investigation (with vbe debugger) told me that dll calling command is the error. I will try the DebugDiag today.

thanks again

Lert
Pianapitham  Thursday, November 26, 2009 9:28 AM

You can use google to search for other answers

Custom Search

More Threads

• VB-DLL incopatibility VISTA/XP
• Intellisense using Word Dictionary
• .Net Component in VB6.0
• vb5 to vb2005 express
• Capturing TAB Key and subsequent events
• Mixing Err.Raise and Exceptions
• Problem with a class library (ActiveX)
• Windows Forms and ActiveX DLL
• .net ListView and groups interop to vb6
• Feasability Study to help Management decide on VB6 VB.Net Upgrade