[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


VB6 compiled code calls assembly code .DLL = Invalid Page Fault in KERNEL32.DLL

Posted on 2003-11-13
Medium Priority
Last Modified: 2007-12-19
I've got a VB6 application under Win98 that is comprised of a simple form with a single button, the declarations for an external .dll, and a function call to the dll.

The DLL was written in assembly and performs communication with the parallel port to custom hardware.  Everything works fine within the VB6 IDE (development environment) however once the VB6 compiled executable is created (the DLL remains the same) and executed it crashes.

I've narrowed it down to the specific assembly instruction that causes it to crash:

I've tried various combinations and work arounds but it seems any MOV instruction that places something in the BX register (e.g. MOV BX,CX etc) causes it to crash.

The actual error message received is:
ApplicationName caused an invalid page fault in module KERNEL32.DLL at blablabla

This seems rather odd as the MOV command is rather innocuous.  Why would it crash in Kernel32?? I would think if there was some sort of stack error caused by the assembly code that it wouldn't work in the IDE but it works GREAT until you create an executable.

Question by:cosbit
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2

Expert Comment

ID: 9745743
This is just a guess that you might want to explore.

Perhaps CX points to a memory location outside of the space allocated to your app? Thus you are trying to write to another app's memory space.  With Win98 you do get the memory protection, so this could cause the crash.


Author Comment

ID: 9745889
Thanks.  I was trying to think about something along these lines but CX & AH are registers so the data they contain should not be in protected memory.  

Why would it work in the IDE but not the compiled exe ?

Thank you.
LVL 16

Assisted Solution

Richie_Simonetti earned 400 total points
ID: 9747263
some Qs:
Asm dll is 32-bit, right?
Could be a time problem? I mean, in IDE all things works slow than a compiled exe so some state is reached at proper time in IDE but when you run the exe, that "state" is not available yet (Maybe initialization of custom hardware)
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 9749442
I assume the asm DLL is 32-bit, the first declaration in the source is:"SEGMENT code USE32"

I investigated this adding by adding delays to the compiled code but it didn't seem to help and still crashed while processing the MOV BH,AL command.

Are there any debugging/development tools that anyone would recommend to help with this?  I've got Visual Studio 6.0 but I'm not familiar with some of the tools included with it.

Thank you.

Author Comment

ID: 9751843
I just noticed if I change the VB6 Project Properties from Native Code to P-Code the error message changes from an IPF in KERNEL32.DLL to MSVBVM60.DLL.

Then when I click "DEBUG" and go into Visual Studio, I get the following error message:
Unhandled Exception 0xc000005 Access Violation.

Googling this : http://lists.wxwindows.org/archive/wx-users/msg05722.html

Does this ring a bell with anyone?

Accepted Solution

robdogg10 earned 1600 total points
ID: 9751903
"Unhandled Exception 0xc000005 Access Violation" is just what I was saying.  It is going into some other apps memory space.  That's what access violation means.  

Another suggestion is kind of obvious, but did you disable all the optimizations in the VB compiler?  
LVL 16

Expert Comment

ID: 9763131
I am just curious, what was the result?

Author Comment

ID: 9765841
Oh Sorry... For some reason my comment didn't post.

I got it to work after being sure to save all the registers (PUSH/POP) in my assembly program.
Although at the moment, I'm struggling because I overwrote some changes and now there is some bug still in there.

This URL helped:


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question