Solved

Problem with interrupt calls in Delphi 4

Posted on 1998-10-31
6
314 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
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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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