Lazarus 写一个 dll 以 json 的方式输出 smbios 信息

Lazarus 写一个 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);
    

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,981评论 19 139
  • 一、温故而知新 1. 内存不够怎么办 内存简单分配策略的问题地址空间不隔离内存使用效率低程序运行的地址不确定 关于...
    SeanCST阅读 7,883评论 0 27
  • 老头昨天掉了身份证,急得火烧火燎,连夜写下寻物启事。寻物启事被张贴在小区门口,字迹铁画银钩,如笔走龙蛇般不失气势。...
    酽茶如酒阅读 390评论 0 0
  • 后来茫茫人海中我仿佛又遇到了她,只是彼此褪去了昔日的青涩。旧时光里的人总是像老电影里面的镜头不断在脑海中闪过,...
    公子_瑾瑜阅读 222评论 0 1
  • 谈不上又开始,因为就未曾真正开始过,只是在自己的脑海中构思过,曾经在新浪博客上发过一篇就偃旗息鼓了,这次i am ...
    铁哥allen阅读 405评论 1 1