This is my first real  attempt at using structures in assembly. I am trying to access the data in SYSTEM_POWER_STATUS structure but having error when I try to build it.
Here are the pieces of code I am using:
.data?
Posted on 2010-02-17 13:50:49 by Biorat
Heh sorry, I accidently hit post early  :oops:

This is my first real  attempt at using structures in assembly. I am trying to access the data in SYSTEM_POWER_STATUS structure but having error when I try to build it.
Here are the pieces of code I am using:

include \masm32\include\windows.inc   
include \masm32\macros\macros.asm     

include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data?
SPS SYSTEM_POWER_STATUS <>

.code
...
invoke GetSystemPowerStatus,ADDR SPS
mov eax,SPS.BatteryTimeLeft                    ;Just trying to read some data from structure


I am getting an saying "undefined symbol : BatteryTimeLeft"

http://msdn.microsoft.com/en-us/library/aa373232(VS.85).aspx SYSTEM_POWER_STATUS on MSDN
http://msdn.microsoft.com/en-us/library/aa372693(VS.85).aspx GetSystemPowerStatus on MSDN
Now, I realize I may be doing something completely wrong and any help would be appreciated
Posted on 2010-02-17 14:03:03 by Biorat
Biorat,

BatteryLifeTime, probably.
Posted on 2010-02-17 14:18:46 by baldr
:oops:
just goes to show sometimes all you need is another pair of eyes... Thanks
Posted on 2010-02-17 14:28:17 by Biorat
No need for the [:oops:]. Little errors are a part of life and we just have to live with them. Thinking back to all the code on I've posted over the years, I can't think of one single time that I haven't had to correct something afterwards. lol

With production projects, you have the resources of paid alpha and beta testers to work out any little errors before release. We don't really have that luxury with hobby and low/no profit projects. That's one of the things that make sites like this one such a valuable resource. So no need to feel embarrassed or ashamed for such a code snafu.
Posted on 2010-02-17 15:15:41 by Synfire
Alright, I am able to output the value to screen so that I can confirm that is correct. The value for example is '9173' which is the number of seconds the battery has left. Now im just trying to convert that to minutes and I cant. So here is the relevant code:

.data
SIXTY DWORD 60

.code
start:
  ...

invoke GetSystemPowerStatus,ADDR SPS ; Get system power status
        .if  SPS.BatteryLifeTime == -1
;show message...
.else
                xor eax,eax
mov eax, SPS.BatteryLifeTime
div SIXTY
.endif

        ...


The program just stops at 'div SIXTY' and wont execute anything after. What am I doing wrong???

I hate "little" hurtles like this when im learning something, cause I know its going to be something simple
Posted on 2010-02-18 15:15:06 by Biorat

first, need to know the div instruction will take edx:eax as the input - so set edx to zero.
after operation, eax will contain quotient, and edx will contain remainder.

xor edx,edx ; cool way to set a register to zero
mov ebx,60 ; no need for a constant, if we have a spare register
div ebx

;now eax is the answer, and edx is any remainder

Posted on 2010-02-18 15:44:32 by Homer