Page 1 of 1

GetFirmwareType - Why always return 0?

Posted: Wed Jun 26, 2024 4:33 pm
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

Re: GetFirmwareType - Why always return 0?

Posted: Wed Jun 26, 2024 4:38 pm
by jacdelad
The functions return value is an error code. You need to specify your structure as parameter.

Re: GetFirmwareType - Why always return 0?

Posted: Wed Jun 26, 2024 4:40 pm
by hoangdiemtinh
How? Can you explain it to me?

Re: GetFirmwareType - Why always return 0?

Posted: Wed Jun 26, 2024 4:41 pm
by infratec
If you read what you post as link, then you will notice why it is not working.
This function has a parameter :!:

Re: GetFirmwareType - Why always return 0?

Posted: Wed Jun 26, 2024 4:41 pm
by infratec
The parameter is a pointer <-> integer

Re: GetFirmwareType - Why always return 0?

Posted: Wed Jun 26, 2024 4:44 pm
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 , ...