Seite 1 von 1

Buffersize ermitteln

Verfasst: 04.03.2006 23:08
von PBZecke
Hallo!

Ich habe lange nichts mehr mit PB gemacht, und sehe deshalb den Wald vor lauter Bäumen nicht! Folgender Code funktioniert (PB4):

Code: Alles auswählen

Structure SYSTEM_POWER_CAPABILITIES
  PowerButtonPresent.b
  SleepButtonPresent.b
  LidPresent.b
  SystemS1.b
  SystemS2.b
  SystemS3.b
  SystemS4.b
  SystemS5.b
  HiberFilePresent.b
  FullWake.b
  VideoDimPresent.b
  ApmPresent.b
  UpsPresent.b
  ThermalControl.b
  ProcessorThrottle.b
  ProcessorMinThrottle.b
  ProcessorMaxThrottle.b
  spare2.b
  DiskSpinDown.b
  spare3.b
  SystemBatteriesPresent.b
  BatteriesAreShortTerm.b
  BatteryScale.l
  AcOnLineWake.l
  SoftLidWake.l
  RtcWake.l
  MinDeviceWakeState.l
  DefaultLowLatencyWake.l
EndStructure

#SystemPowerCapabilities = 4
  


Define SYSINF.SYSTEM_POWER_CAPABILITIES


If OpenLibrary(0, "PowrProf.DLL")
  *F = GetFunction(0, "CallNtPowerInformation")
  If *F
    CallFunctionFast(*F, #SystemPowerCapabilities, 0, 0, @SYSINF,  100)
    Debug SYSINF\SystemBatteriesPresent
    Debug SYSINF\HiberFilePresent
    Debug sysinf\ProcessorMaxThrottle
  EndIf
  
  CloseLibrary(0)
EndIf
jedoch ist die Zeile

Code: Alles auswählen

CallFunctionFast(*F, #SystemPowerCapabilities, 0, 0, @SYSINF,  100)
nicht ganz sauber da ich den OuputBuffer einfach mit 100 angebe. Wie ermittle ich die korrekte Größe des Buffers? SizeOf liefert eine falsche Größe bzw ich setze es falsch ein!

Verfasst: 04.03.2006 23:52
von Friedhelm
Versucht man ihr mit

Code: Alles auswählen

Structure SYSTEM_POWER_CAPABILITIES 
  PowerButtonPresent.b 
  SleepButtonPresent.b 
  LidPresent.b 
  SystemS1.b 
  SystemS2.b 
  SystemS3.b 
  SystemS4.b 
  SystemS5.b 
  HiberFilePresent.b 
  FullWake.b 
  VideoDimPresent.b 
  ApmPresent.b 
  UpsPresent.b 
  ThermalControl.b 
  ProcessorThrottle.b 
  ProcessorMinThrottle.b 
  ProcessorMaxThrottle.b 
  spare2.b 
  DiskSpinDown.b 
  spare3.b 
  SystemBatteriesPresent.b 
  BatteriesAreShortTerm.b 
  BatteryScale.l 
  AcOnLineWake.l 
  SoftLidWake.l 
  RtcWake.l 
  MinDeviceWakeState.l 
  DefaultLowLatencyWake.l 
EndStructure 

#SystemPowerCapabilities = 4 
  


Define SYSINF.SYSTEM_POWER_CAPABILITIES 

Mesisch.s=Space(100)


If OpenLibrary(0, "PowrProf.DLL") 
  *F = GetFunction(0, "CallNtPowerInformation") 
  If *F 
    CallFunctionFast(*F, #SystemPowerCapabilities, 0, 0, @SYSINF,SizeOf(SYSINF)) 
    
    Debug SYSINF\SystemBatteriesPresent 
    Debug SYSINF\HiberFilePresent 
    Debug sysinf\ProcessorMaxThrottle 
  EndIf 
  
  CloseLibrary(0) 
EndIf 
mit freundlichen Gruß
Friedhelm

Verfasst: 05.03.2006 00:11
von PBZecke
Hmm...

Code: Alles auswählen

CallFunctionFast(*F, #SystemPowerCapabilities, 0, 0, @SYSINF,SizeOf(SYSINF))
hatte ich auch probiert, und geht nicht!

Und was soll

Code: Alles auswählen

Mesisch.s=Space(100)
:roll:

Trotzdem danke!

Verfasst: 05.03.2006 02:38
von edel
Die Struktur ist falsch.
typedef struct {
BOOLEAN PowerButtonPresent;
BOOLEAN SleepButtonPresent;
BOOLEAN LidPresent;
BOOLEAN SystemS1;
BOOLEAN SystemS2;
BOOLEAN SystemS3;
BOOLEAN SystemS4;
BOOLEAN SystemS5;
BOOLEAN HiberFilePresent;
BOOLEAN FullWake;
BOOLEAN VideoDimPresent;
BOOLEAN ApmPresent;
BOOLEAN UpsPresent;
BOOquoteLEAN ThermalControl;
BOOLEAN ProcessorThrottle;
UCHAR ProcessorMinThrottle;
UCHAR ProcessorMaxThrottle;
UCHAR spare2[4];
BOOLEAN DiskSpinDown;
UCHAR spare3[8];
BOOLEAN SystemBatteriesPresent;
BOOLEAN BatteriesAreShortTerm;
BATTERY_REPORTING_SCALE BatteryScale[3];
SYSTEM_POWER_STATE AcOnLineWake;
SYSTEM_POWER_STATE SoftLidWake;
SYSTEM_POWER_STATE RtcWake;
SYSTEM_POWER_STATE MinDeviceWakeState;
SYSTEM_POWER_STATE DefaultLowLatencyWake;

} SYSTEM_POWER_CAPABILITIES, *PSYSTEM_POWER_CAPABILITIES;

Verfasst: 05.03.2006 09:04
von Friedhelm
PBZecke hat geschrieben:
Und was soll

Code: Alles auswählen

Mesisch.s=Space(100)
:roll:

Trotzdem danke!

Hatte vergessen Vergessen zu löschen!. :oops: :oops: 8)

Mfg
Friedhelm

Verfasst: 05.03.2006 12:30
von PBZecke
hallodri hat geschrieben:Die Struktur ist falsch.
OK, aber wie setze ich das richtig in PureBasic um?

Verfasst: 05.03.2006 14:47
von edel
spare2.b[4] ,spare3.b[8]
usw .

Verfasst: 05.03.2006 15:18
von PBZecke
Ja, stimmt! SizeOf liefert schon die richtige Größe des Buffers, und der ist eben wegen der falschen Structure zu klein, was das ganze eben Scheitern ließ!

Danke, erledigt! :)