GetFirmwareType - Why always return 0?

Just starting out? Need help? Post your questions and find answers here.
hoangdiemtinh
User
User
Posts: 97
Joined: Wed Nov 16, 2022 1:51 pm

GetFirmwareType - Why always return 0?

Post by hoangdiemtinh »

Good afternoon.

I am new to PB. My primary language is not US/UK. I am using Google Translate.

I am practicing writing code to distinguish whether Windows is booting using FW MBR or UEFI.

Code: Select all

Enumeration FIRMWARE_TYPE
  #FirmwareTypeUnknown
  #FirmwareTypeBios
  #FirmwareTypeUefi
  #FirmwareTypeMax
EndEnumeration

Prototype.i Get_FirmwareType()

If OpenLibrary(0, "Kernel32.dll")
  FW.Get_FirmwareType = GetFunction(0, "GetFirmwareType")
  Debug FW()
EndIf

Relate to:
https://learn.microsoft.com/en-us/windo ... dfrom=MSDN
https://learn.microsoft.com/en-us/windo ... mware_type
PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
I love PB5 vs PB6 :)
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: GetFirmwareType - Why always return 0?

Post by jacdelad »

The functions return value is an error code. You need to specify your structure as parameter.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
hoangdiemtinh
User
User
Posts: 97
Joined: Wed Nov 16, 2022 1:51 pm

Re: GetFirmwareType - Why always return 0?

Post by hoangdiemtinh »

How? Can you explain it to me?
PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
I love PB5 vs PB6 :)
infratec
Always Here
Always Here
Posts: 7575
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: GetFirmwareType - Why always return 0?

Post by infratec »

If you read what you post as link, then you will notice why it is not working.
This function has a parameter :!:
infratec
Always Here
Always Here
Posts: 7575
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: GetFirmwareType - Why always return 0?

Post by infratec »

The parameter is a pointer <-> integer
infratec
Always Here
Always Here
Posts: 7575
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: GetFirmwareType - Why always return 0?

Post by infratec »

Code: Select all

Enumeration FIRMWARE_TYPE
  #FirmwareTypeUnknown
  #FirmwareTypeBios
  #FirmwareTypeUefi
  #FirmwareTypeMax
EndEnumeration

Prototype.i Get_FirmwareType(*FirmwareType)

If OpenLibrary(0, "Kernel32.dll")
  FW.Get_FirmwareType = GetFunction(0, "GetFirmwareType")
  
  Define FirmwareType.i
  
  If FW(@FirmwareType)
    Debug FirmwareType
  Else
    Debug "Error"
  EndIf
EndIf
Really, you need to understand what you are reading. And you need to read, read , ...
Post Reply