Einzelnen Beitrag anzeigen

Horst0815

Registriert seit: 23. Mai 2011
Ort: Görlitz
150 Beiträge
 
Delphi XE Starter
 
#3

AW: Hilfe bei übersetzung einer CPP schleife

  Alt 19. Jul 2012, 18:07
Für den Rest noch jemand ne Idee?

Delphi-Quellcode:
Function init_raw_smbios_data: Boolean;
var // These are all needed for the WMI querying process
  p_Locator: ISWbemLocator;
  p_service: ISWbemServices;
  vNVS: OleVariant;
  p_enumerator, p_instance: OleVariant; // IEnumWbemClassObject;
  dw_count: ULONG;
  variant_bios_data: OleVariant;
  ret: Boolean;
  h_result: HRESULT;
  types: Integer; // CIMTYPE
  p_data: PChar; // unsigned char* p_data
begin
  // zero raw dat memory
  FillChar(global_buffer.smbios_table_data, MAX_DATA, #0);
  // memset(global_buffer.smbios_table_data,0,MAX_DATA);
  ret := false;
  // Initialize COM.
  h_result := CoInitializeEx(0, COINIT_MULTITHREADED);
  if (h_result < 0) then
    Result := false; // Program has failed.
  // Obtain the initial locator to Windows Management on a particular host computer.
  p_Locator := nil;
  // h_result := CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,IID_IWbemLocator,{ (LPVOID *) }p_locator);
  if h_result < 0 then
  begin
    CoUninitialize;
    Result := false; // Program has failed.
  end;
  p_service := nil;
  // Connect to the root\cimv2 namespace with thecurrent user and obtain pointer pSvc
  // to make IWbemServices calls.
  // h_result := p_locator.ConnectServer('ROOT\WMI', '', '', '', '', '', 0,&p_service); //vNVS
  if (h_result < 0) then
  begin
    p_Locator._Release;
    CoUninitialize();
    Result := false; // Program has failed.
  end;
  // Set the IWbemServices proxy so that impersonation of the user (client) occurs.
  h_result := CoSetProxyBlanket(p_service, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,
    nil, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, nil, EOAC_NONE);
  if h_result < 0 then
  begin
    p_service._Release;
    p_Locator._Release;
    CoUninitialize();
    Result := false; // Program has failed.
  end;
  p_enumerator := 0;
  // h_result := p_service.InstancesOf('MSSMBios_RawSMBiosTables', 0, &p_enumerator);
  if h_result < 0 then
  begin
    p_service._Release;
    p_Locator._Release;
    CoUninitialize();
    Result := false; // Program has failed.
  end
  else
  begin
    repeat
    begin
      p_instance := 0;
      h_result := p_enumerator.Next(WBEM_INFINITE, 1, &p_instance, &dw_count);
      if h_result >= 0 then
      begin
        VariantInit(&variant_bios_data);
        h_result := p_instance.Get('SmbiosMajorVersion', 0, &variant_bios_data,
          &types, 0);
        if h_result < 0 then
          VariantClear(&variant_bios_data)
        else
        begin
          // global_buffer.smbios_major_version := {Char}(variant_bios_data.iVal);
          VariantInit(&variant_bios_data);
          h_result := p_instance.Get('SmbiosMinorVersion', 0,
            &variant_bios_data, &types, 0);
          if h_result < 0 then
            VariantClear(&variant_bios_data)
          else
          begin
            // global_buffer.smbios_minor_version = (unsigned char)variant_bios_data.iVal;
            VariantInit(&variant_bios_data);
            h_result := p_instance.Get('SMBiosData', 0, &variant_bios_data,
              &types, 0);
            if h_result >= 0 then
            begin

              // if ( ( VT_UI1 | VT_ARRAY ) != variant_bios_data.vt ) then
              // begin
              // end
              // else
              begin
                // SAFEARRAY* p_array = NULL;
                // p_array = V_ARRAY(&variant_bios_data);
                // p_data := (unsigned char *)p_array->pvData;
                //
                // global_buffer.length := {p_array->}rgsabound[0].cElements;
                if (global_buffer.length >= MAX_DATA) then
                begin
                  WriteLn('Return global_buffer would overflow. Abort initialization of raw SMBIOS data.\n');
                  p_service._Release;
                  p_Locator._Release;
                  CoUninitialize();
                  Result := false;
                end;
                Move(p_data, global_buffer.smbios_table_data,
                  global_buffer.length);
              end;
            end;
            VariantClear(&variant_bios_data);
          end;
        end;
        Exit;
      end;
    end;
    until h_result <> WBEM_S_NO_ERROR;
  end;
  p_service._Release;
  p_Locator._Release;
  CoUninitialize();
  Result := True;
end;
  Mit Zitat antworten Zitat