Einzelnen Beitrag anzeigen

delphin06

Registriert seit: 18. Jun 2006
154 Beiträge
 
#17

Re: Speicher läuft voll bei WMI....

  Alt 23. Sep 2007, 17:19
Ich versteh das alles nich mehr...ich habe den WMI teil jez mal in eine DLL gepackt, die ich dann nachher wieder lade aber irgendwie hat sich nichts geändert...warum?

Hier mal der code der dll:
Delphi-Quellcode:
library WMICall_DLL;

uses
  Sharemem, SysUtils,
  Classes,
  WMIfunctions in 'WMIfunctions.pas';

type
  Twmistring = array [0..30] of array [0..7] of String;

{$R *.res}

function getwmiinfo(comp, namespace, username, pass, query: String; vista: Boolean):Twmistring;
Var WMIResults: TWMIInfo;
    i, i2: Integer;
    wmidrives:Twmistring;
begin
  {
  Instance
  Caption
  DeviceID
  Partitions
  SerialNumber
  Signature
  Size
  }


  if not WMIGetInfo(comp, namespace, username, pass, Trim(query), WMIResults) then
    begin
      wmidrives[0,0] := 'ERROR';
      Exit;
    end;

  wmidrives[0,0] := '';

  if WMIResults.Instance = nil then
    begin
      Exit;
    end;

  
  //WMIResults.Instance: Anzahl der Instanzen (Laufwerke) (Spalten)
  //WMIResults.PropName: Anzahl der Querys (in dem Fall 6) (Zeilen)

  For i := 0 to Length(WMIResults.Instance) do
    If i = 0 Then
      wmidrives[i, 0] := 'Instance'
    Else
      wmidrives[i, 0] := IntToStr(i);

  if vista then
    begin
      For i2 := 0 to High(WMIResults.PropName) do
        Begin
          wmidrives[0, i2 + 1] := WMIResults.PropName[i2]; //6
          For i := 0 to High(WMIResults.Instance) do
            begin
              wmidrives[i + 1, i2 + 1] := WMIRead(WMIResults, i, i2);
            end;
        End;
    end
  else
    begin
      For i2 := 0 to High(WMIResults.PropName) do
        Begin
          if i2 >= 3 then
            begin
              wmidrives[0, i2 + 2] := WMIResults.PropName[i2];
              For i := 0 to High(WMIResults.Instance) do
                wmidrives[i + 1, i2 + 2] := WMIRead(WMIResults, i, i2);
            end
          else
            begin
              wmidrives[0, i2 + 1] := WMIResults.PropName[i2];
              For i := 0 to High(WMIResults.Instance) do
                wmidrives[i + 1, i2 + 1] := WMIRead(WMIResults, i, i2);
            end;
        End;
    end;

  for i := 1 to Length(WMIResults.Instance) do
    begin
      if wmidrives[i, 6] = 'NULLthen //Size
        wmidrives[i, 6]:='0';
      if wmidrives[i, 3] = 'NULLthen //Partitions
        wmidrives[i, 3]:='0';
      if length(wmidrives[i, 5])<=1 then //Sig
        wmidrives[i, 5]:='-';
      if length(wmidrives[i, 4])<=1 then//Serial
        wmidrives[i, 4]:='-';
    end;

end;


exports
  getwmiinfo;

begin
end.
natürlich ist die WMI.pas da mit eingebunden!

Aufruf dann aus hauptprogramm über:

Delphi-Quellcode:
type
  Twmistring = array [0..30] of array [0..7] of String;

type
  Tgetwmiinfo = function(comp, namespace, username, pass, query: String; vista: Boolean):Twmistring;




...




function getwmidriveinfo(comp, namespace, username, pass, query: String; vista: Boolean):Twmistring;
var WMIFunktion: Tgetwmiinfo;
    Handle: THandle;
begin
  Handle := LoadLibrary(PChar(ExtractFilePath(ParamStr(0))+'WMICall_DLL.dll'));
  if Handle <> 0 then
  begin
    @WMIFunktion := GetProcAddress(Handle, 'getwmiinfo');
    if @WMIFunktion <> nil then
      begin
        result:=WMIFunktion(comp, namespace, username, pass, query, vista);
      end;
    FreeLibrary(Handle);
  end;
end;


...
Was mache ich nur falsch? nach dem laden der dll erhöht sich der speicherbedarf (is ja klar) aber nach dem freigeben wird dieser nicht komplett wieder frei! Warum nicht?
  Mit Zitat antworten Zitat