Solved

Problem with interrupt calls in Delphi 4

Posted on 1998-10-31
6
317 Views
Last Modified: 2010-04-06
Hi,

I have a snippet of code here which queries to see if laptop power management is present and if so, it returns the battery power remaining.  This worked fine under Delphi 1 but under Delphi 4 I get (I think) an access violation.  :-(

I understand from Madshi (comment below) that I can't directly call an Interrupt from a Delphi 4 app.  Can anyone tell me how I can either call a 16 bit DLL or whether there is a Win32 function call to obtain the battery level information?

Thank you!
MP

Function PowerMan:Integer;
Var
  Fault,Batt,Life:Byte;
begin
  asm
    mov fault,00h
    mov ax,5300h
    mov bx,0000h
    int 15h
    jc @err
    mov ax,530ah
    mov bx,0001h
    int 15h
    mov batt,bl
    mov life,cl
    jc @err
    jmp @done
    @err: mov fault,AH
    @done: nop
  end;

  If (Fault=0) And (Life In [0..100]) Then
    PowerMan:=Life
    Else PowerMan:=-1;  // no power info
End;
0
Comment
Question by:mikepj
[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
  • 3
  • 2
6 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1345142
Mike,

in 32bit windows you MUST NOT call dos interrupts directly. That just doesn't work. So if you really need this call and if there is no win32 equivalent function that fulfills your needs, you'll have to work with thunks...
But, man, that's quite hard stuff. You'll have to write a 16 bit dll that exports a function that does your interrupt calls (you'll need a 16 bit compiler for this purpose) and then you'll have to write a thunk in your 32 bit application to be able to call this 16 bit dll function.
Sounds hard? Yes, it is.   :-(
If you need more informations about thunking: I've a little example function, but I think there are other experts who know more about it. I'm thinking of Igor ("inter") for example. He's talking about thunking in another question that is still open (oops, I don't have the question address in the moment). Igor, are you there?

Regards, Madshi.
0
 
LVL 2

Author Comment

by:mikepj
ID: 1345143
Edited text of question
0
 
LVL 2

Author Comment

by:mikepj
ID: 1345144
Adjusted points to 100
0
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!

 
LVL 4

Accepted Solution

by:
dwwang earned 100 total points
ID: 1345145
If your Notebook support Win95 Power Management, you can directly call GetSystemPowerStatus:

BOOL GetSystemPowerStatus(
    LPSYSTEM_POWER_STATUS lpSystemPowerStatus      
   );      

The structure  SystemPowerStatus contains all the infomation concerning system power status
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1345146
By the way, Delphi4 will surely have a port of this API, just call it directly with necessary unit used.
0
 
LVL 2

Author Comment

by:mikepj
ID: 1345147
Thank you for your help!

[I was about 5 minutes from discovering this myself after searching for about 2 hours!]

Best regards,
MP

0

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

710 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