Solved

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

Posted on 2003-11-13
8
654 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
  • 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now