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)
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

762 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