Solved

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

Posted on 2003-11-13
8
679 Views
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:
MOV BH,AL

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.

Thanks!
Bob
0
Comment
Question by:cosbit
[X]
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
8 Comments
 
LVL 1

Expert Comment

by:robdogg10
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.

0
 

Author Comment

by:cosbit
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.
0
 
LVL 16

Assisted Solution

by:Richie_Simonetti
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)
0
Technology Partners: 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

by:cosbit
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.
0
 

Author Comment

by:cosbit
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?
Thx
0
 
LVL 1

Accepted Solution

by:
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?  
0
 
LVL 16

Expert Comment

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

Author Comment

by:cosbit
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:
http://www.geocities.com/emami_s/assembly.html

0

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…

749 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