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

Posted on 2003-11-13
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 100 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 :

Does this ring a bell with anyone?

Accepted Solution

robdogg10 earned 400 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

691 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