Fórum Rotina para obter Temperatura da cpu dá erro #255390
21/10/2004
0
interface
uses
Windows, SysUtils, Forms, Dialogs, Classes, ActiveX, ComObj;
function GetObject(Value: String): IUnknown;
procedure DisplayTemperatures;
implementation
procedure DisplayTemperatures;
var ovObjSet: OleVariant;
ovObj: OleVariant;
ovEnum: OleVariant;
// Hack cast - as WMI really exposes the collection as IEnumWbemClassObject,
// which is identical to IEnumXXXX collections
pvEnum: IEnumVariant;
dwFetch: Cardinal;
begin
ovObjSet:=GetObject(´winmgmts:{impersonationLevel=impersonate}´) as IDispatch;
ovObjSet:=ovObjSet.InstancesOf(´Win32_TemperatureProbe´);
ovEnum:=ovObjSet._NewEnum;
pvEnum:=IEnumVariant(TVarData(ovEnum).VUnknown);
pvEnum.Reset;
while (pvEnum.Next(1, ovObj, dwFetch) = S_OK) do
begin
// CurrentReading
// Data type: sint32
// Access type: Read-only
// Qualifiers: Units(Tenths of degrees Centigrade)
// Current value indicated by the sensor. This property is inherited from CIM_NumericSensor.
ShowMessage(ovObj.CurrentReading);
ovObj:=Unassigned;
end;
pvEnum:=nil;
ovEnum:=Unassigned;
ovObjSet:=Unassigned;
end;
function GetObject(Value: String): IUnknown;
var pUnk: IUnknown;
pmk: IMoniker;
pbc: IBindCtx;
cbEaten: LongInt;
clsid: TGUID;
begin
// Check value to determine if this is a programmatic id or a moniker
if (CLSIDFromProgID(PWideChar(WideString(Value)), clsid) = S_OK) then
begin
// Attempt to get the active object, clear the result on failure
if not(GetActiveObject(clsid, nil, result) = S_OK) then result:=nil;
end
else
begin
// Moniker name
if (CreateBindCtx(0, pbc) = S_OK) then
begin
if (MkParseDisplayName(pbc, StringToOleStr(Value), cbEaten, pmk) = S_OK) then
begin
// Attempt to bind the moniker, clear the result on failure
if not(BindMoniker(pmk, 0, IUnknown, result) = S_OK) then result:=nil;
// Release the moniker
pmk:=nil;
end;
// Release the bind context
pbc:=nil;
end;
end;
end;
end.
Está dando uns erros,o que está errado?
Milk
Curtir tópico
+ 0Posts
21/10/2004
Khundalini
[]s
Rubem Rocha
Manaus, AM
Gostei + 0
21/10/2004
Milk
begin
{Diz que são tipos incompativeis ´HGDIOBJ AND STRING´,aponta para a proxima linha}
ovObjSet:=GetObject(´winmgmts:{impersonationLevel=impersonate}´) as IDispatch;
ovObjSet:=ovObjSet.InstancesOf(´Win32_TemperatureProbe´);
ovEnum:=ovObjSet._NewEnum;
Gostei + 0
21/10/2004
Ipc$
Coloque:
Unitx.GetObject // onde Unitx é o nome da sua unit.
Gostei + 0
21/10/2004
Milk
//"Unsastified forward or external declaration:tform1.getobject´ " na proxima linha function GetObject(Value: String): IUnknown; procedure DisplayTemperatures;
Gostei + 0
21/10/2004
Ipc$
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)