16,748
社区成员
发帖
与我相关
我的任务
分享
function FindExe(AName: string): Boolean;
var
v_ProcessSnap: THandle;
v_pe32: TProcessEntry32;
v_Str: String;
begin
Result := False;
v_ProcessSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (v_ProcessSnap = INVALID_HANDLE_VALUE) then Exit;
v_pe32.dwSize := sizeof(PROCESSENTRY32);
if Process32First(v_ProcessSnap, v_pe32) then
repeat
v_Str := v_pe32.szExeFile;
if v_Str = AName then
begin
Result := True;
Break;
end;
until not Process32Next(v_ProcessSnap, v_pe32);
CloseHandle(v_ProcessSnap);
end;
unit CUP;
interface
uses Windows, SysUtils,Tlhelp32;
type
TCPUID=array[1..4]of LongInt;
TVendor=array[0..11] of Char;
function IsCPU_Available:Boolean;register;
function GetCPUID:TCPUID;assembler;register;
function GetCPUVendor:TVendor;assembler;register;
implementation
function IsCPU_Available:Boolean;register;
asm
pushfd
pop eax
mov edx,eax
xor eax,ID_BIT
push eax
popfd
pushfd
pop eax
xor eax,edx
jz @Exit
mov al,True
@Exit:
end;
function GetCPUID:TCPUID;assembler;register;
asm
PUSH EBX
PUSH EDI
MOV EDI,EAX
MOV EAX,1
DW $A20F
STOSD
MOV EAX,EBX
STOSD
MOV EAX,ECX
STOSD
MOV EAX,EDX
STOSD
POP EDI
POP EBX
end;
function GetCPUVendor:TVendor;assembler;register;
asm
PUSH EBX
PUSH EDI
MOV EDI,EAX
MOV EAX,0
DW $A20F
MOV EAX,EBX
XCHG EBX,ECX
MOV ECX,4
@1:
STOSB
SHR EAX,8
LOOP @1
MOV EAX,EDX
MOV ECX,4
@2:
STOSB
SHR EAX,8
LOOP @2
MOV EAX,EBX
MOV ECX,4
@3:
STOSB
SHR EAX,8
LOOP @3
POP EDI
POP EBX
end;
end.
unit UnitManagedObject;
interface
uses
Windows
;
type
TManagedObject = class(TObject)
{Management Properties}
private
FManagementCount : Integer; //对象引用计数
protected
function Detach: Integer;
public
{structor}
constructor Create;
public
{Management}
procedure Free;
function Attach:TManagedObject;
end;
implementation
{TManagedBaseObject}
{structor}
constructor TManagedObject.Create;
begin
Inherited Create;
FManagementCount := 1;
end;
{Management}
function TManagedObject.Attach : TManagedObject;
begin
Result := Nil;
if InterlockedIncrement(FManagementCount) = 1 then
begin
InterlockedDecrement(FManagementCount);
Exit;
end;
Result := self;
end;
function TManagedObject.Detach : Integer;
begin
Result := InterlockedDecrement(FManagementCount);
end;
procedure TManagedObject.Free;
begin
if Detach>0 then
Exit;
Inherited;
end;
end.