Solved

Problem with interrupt calls in Delphi 4

Posted on 1998-10-31
6
311 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
  • 3
  • 2
6 Comments
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
Comment Utility
Edited text of question
0
 
LVL 2

Author Comment

by:mikepj
Comment Utility
Adjusted points to 100
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Accepted Solution

by:
dwwang earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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