Einzelnen Beitrag anzeigen

Horst0815

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

AW: Hilfe bei übersetzung einer CPP schleife

  Alt 20. Jul 2012, 17:22
danke für die Tips

aber ein Paar sachen fehlen mir noch daraus werd ich nicht schlau

Code:
                        SAFEARRAY* p_array = NULL;
                        p_array = V_ARRAY(&variant_bios_data);
                        unsigned char* p_data = (unsigned char *)p_array->pvData;
Delphi-Quellcode:
         
                 p_array := PSafeArray(TVariantArg(variant_bios_data).ppArray);
                // p_data := (unsigned char *)p_array->pvData;//Byte??
                 global_buffer.length := p_array->rgsabound[0].cElements;

was bedeutet -> im Code


Komplett siehts erstmal so aus

Delphi-Quellcode:
Function init_raw_smbios_data: Boolean;
var // These are all needed for the WMI querying process
  p_Locator: ISWbemLocator;
  p_service: ISWbemServices;
  p_enumerator, p_instance: OleVariant; // IEnumWbemClassObject?;
  dw_count: ULONG;
  variant_bios_data: OleVariant;
  ret: Boolean;
  h_result: HRESULT;
  types: Integer; // CIMTYPE
  p_data: PByte; // unsigned char* p_data Wirkklich ein PByte?
  p_array: PSAFEARRAY;

  Locator: ISWbemLocator;
  Services: ISWbemServices;
begin
  // zero raw dat memory
  FillChar(global_buffer.smbios_table_data, MAX_DATA, #0);
  ret := false;
  Result := false;
  // Initialize COM.
  h_result := CoInitializeEx(0, COINIT_MULTITHREADED);
  if (h_result < 0) then
    Exit; // 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)); //Inkompatible Typen: 'IInterface' und 'Integer'
  if h_result < 0 then
  begin
    CoUninitialize;
    Exit; // 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); //Inkompatible Typen: 'HRESULT' und 'ISWbemServices'
  if (h_result < 0) then
  begin
    p_Locator._Release;
    CoUninitialize();
    Exit; // 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();
    Exit; // Program has failed.
  end;
  p_enumerator := 0;
  h_result := p_service.InstancesOf('MSSMBios_RawSMBiosTables', 0,
    p_enumerator); // Inkompatible Typen: 'HRESULT' und 'ISWbemObjectSet'
  if h_result < 0 then
  begin
    p_service._Release;
    p_Locator._Release;
    CoUninitialize();
    Exit; // 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 := 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 := 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 or VT_ARRAY) <> variant_bios_data.vt then
              begin
              //Habs erstmal stur mit übersetzt
              end
              else
              begin
                p_array := PSAFEARRAY(TVariantArg(variant_bios_data).ppArray);
                // 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();
                  Exit;
                end;
                Move(p_data, global_buffer.smbios_table_data,
                  global_buffer.length);
              end;
            end;
            VariantClear(variant_bios_data);
          end;
        end;
        Break;
      end;
    end;
    until h_result <> WBEM_S_NO_ERROR;
  end;
  p_service._Release;
  p_Locator._Release;
  CoUninitialize();
  Result := True;
end;
  Mit Zitat antworten Zitat