Lazarus 寫一個(gè) dll 以 json 的方式輸出 smbios 信息

Lazarus 寫一個(gè) dll 以 json 的方式輸出 smbios 信息

library smbios;

{$mode objfpc}{$H+}

uses
  Classes, SysUtils, fpjson, uSMBIOS;

function GetSMBIOS(dest: PAnsiChar):integer; stdcall;
var
  jObject: TJSONObject;
  jArray: TJSONArray;
  SMBios: TSMBios;
  LBIOS   : TBiosInformation;
  OEMStr  : TOEMStringsInformation;
  i : Integer;
begin
  jObject := TJSONObject.Create;
  SMBios:=TSMBios.Create;

  try
    LBIOS:=SMBios.BiosInfo;
    jObject.Add('Vendor', LBIOS.VendorStr);
    jObject.Add('Version', LBIOS.VersionStr);
    jObject.Add('Start Segment', IntToHex(LBIOS.RAWBiosInformation^.StartingSegment,4));
    jObject.Add('ReleaseDate', LBIOS.ReleaseDateStr);
    jObject.Add('Bios Rom Size', 64*(LBIOS.RAWBiosInformation^.BiosRomSize+1));

    if LBIOS.RAWBiosInformation^.SystemBIOSMajorRelease<>$ff then
       jObject.Add('System BIOS Major Release', LBIOS.RAWBiosInformation^.SystemBIOSMajorRelease);
    if LBIOS.RAWBiosInformation^.SystemBIOSMinorRelease<>$ff then
       jObject.Add('System BIOS Minor Release', LBIOS.RAWBiosInformation^.SystemBIOSMinorRelease);

    //If the system does not have field upgradeable embedded controller firmware, the value is 0FFh.
    if LBIOS.RAWBiosInformation^.EmbeddedControllerFirmwareMajorRelease<>$ff then
       jObject.Add('Embedded Controller Firmware Major Release', LBIOS.RAWBiosInformation^.EmbeddedControllerFirmwareMajorRelease);
    if LBIOS.RAWBiosInformation^.EmbeddedControllerFirmwareMinorRelease<>$ff then
       jObject.Add('Embedded Controller Firmware Minor Releasee', LBIOS.RAWBiosInformation^.EmbeddedControllerFirmwareMinorRelease);


    if SMBios.HasOEMStringsInfo then
    begin
      jArray := TJSONArray.Create;
      for OEMStr in SMBios.OEMStringsInfo do
        for i:=1 to OEMStr.RAWOEMStringsInformation^.Count do
          jArray.Add(OEMStr.GetOEMString(i));

      jObject.Add('OEM Strings', jArray);

    end;


    StrPLCopy(dest, jObject.AsJSON, 2048);
    // Writeln(jObject.AsJSON);
  finally
    jObject.Free;
    SMBios.Free;
  end;

  Result := 0;

end;

exports
  GetSMBIOS;
end.

#include <catch.hpp>
#include <Windows.h>
#include <iostream>


TEST_CASE("smbios test", "[smbios test]")
{
    typedef int (__stdcall *fn_GetSMBIOS)(char* dest);
    // function GetSMBIOS(dest: PAnsiChar):integer; stdcall; 

    HMODULE hLib = LoadLibrary(L"smbios.dll");
    fn_GetSMBIOS GetSMBIOS = (fn_GetSMBIOS)GetProcAddress(hLib, "GetSMBIOS");

    std::vector<char> buffer(2048);
    GetSMBIOS(&buffer[0]);
    printf(&buffer[0]); 

    FreeLibrary(hLib);
    

}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,612評(píng)論 19 139
  • 一、溫故而知新 1. 內(nèi)存不夠怎么辦 內(nèi)存簡(jiǎn)單分配策略的問題地址空間不隔離內(nèi)存使用效率低程序運(yùn)行的地址不確定 關(guān)于...
    SeanCST閱讀 8,135評(píng)論 0 27
  • 老頭昨天掉了身份證,急得火燒火燎,連夜寫下尋物啟事。尋物啟事被張貼在小區(qū)門口,字跡鐵畫銀鉤,如筆走龍蛇般不失氣勢(shì)。...
    釅茶如酒閱讀 405評(píng)論 0 0
  • 后來茫茫人海中我仿佛又遇到了她,只是彼此褪去了昔日的青澀。舊時(shí)光里的人總是像老電影里面的鏡頭不斷在腦海中閃過,...
    公子_瑾瑜閱讀 268評(píng)論 0 1
  • 談不上又開始,因?yàn)榫臀丛嬲_始過,只是在自己的腦海中構(gòu)思過,曾經(jīng)在新浪博客上發(fā)過一篇就偃旗息鼓了,這次i am ...
    鐵哥allen閱讀 443評(píng)論 1 1

友情鏈接更多精彩內(nèi)容