Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

Problem with interrupt calls in Delphi 4

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
mikepj
Asked:
mikepj
  • 3
  • 2
1 Solution
 
MadshiCommented:
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
 
mikepjAuthor Commented:
Edited text of question
0
 
mikepjAuthor Commented:
Adjusted points to 100
0
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.

 
dwwangCommented:
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
 
dwwangCommented:
By the way, Delphi4 will surely have a port of this API, just call it directly with necessary unit used.
0
 
mikepjAuthor Commented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now