?
Solved

Problem with interrupt calls in Delphi 4

Posted on 1998-10-31
6
Medium Priority
?
319 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Accepted Solution

by:
dwwang earned 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

719 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