Rotina para obter Temperatura da cpu dá erro
Peguei esta rotina na net
Está dando uns erros,o que está errado?
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
Curtidas 0
Respostas
Khundalini
21/10/2004
Seria bem melhor se você nos disesse quais são os erros, né companheiro? Assim fica difícil de ajudar. ;-)
[]s
Rubem Rocha
Manaus, AM
[]s
Rubem Rocha
Manaus, AM
GOSTEI 0
Milk
21/10/2004
Foi mal
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
Ipc$
21/10/2004
É pq está sendo chamada GetObject da api de gdi e não da sua unit.
Coloque:
Unitx.GetObject // onde Unitx é o nome da sua unit.
Coloque:
Unitx.GetObject // onde Unitx é o nome da sua unit.
GOSTEI 0
Milk
21/10/2004
Continua dando erro ,agora em outra linha
//"Unsastified forward or external declaration:tform1.getobject´ " na proxima linha function GetObject(Value: String): IUnknown; procedure DisplayTemperatures;
GOSTEI 0
Ipc$
21/10/2004
Coloque forward; nas declarações da interface, ou tire-as da interface e deixe suas implementações no começo da implementation.
GOSTEI 0