Home > Back-end >  BCB how to access the hardware the size of the CPU and memory model of information information?
BCB how to access the hardware the size of the CPU and memory model of information information?

Time:10-08




As shown above, the operating system can obtain information on the size of the CPU and memory model,

So using BCB how to access?

Tested _SYSTEM_INFO and GetSystemInfo, found that the return of the CPU type information is 586, rather than core2, how to do?

CodePudding user response:

Used for inline assembly way, as if using the cpuid instruction
But I feel Windows these parameters are generally registered table can be found directly

CodePudding user response:

Remember you can use WMI for all hardware equipment information,
You can also use the JCL Library (JEDI Library, open source), there are the Hardware unit, can get the Hardware information,

CodePudding user response:

reference 1st floor bigfog response:
used for inline assembly way, as if using the cpuid instruction
But I feel Windows these parameters are generally registries can directly find

This is the cpuid

CodePudding user response:

Let me help you

ClassCPUInfo. CPP

 
# include "classCPUInfo. H"//take CPU information

//# include "classCPUInfo. CPP"//take CPU information

# # ifndef _classCPUInfo_cpp_
# define _classCPUInfo_cpp_

/*
www.plm.hk
*/
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//////////////////////////////////////////////////////////////////////
//Construction/Destruction
//////////////////////////////////////////////////////////////////////

ClassCCPUInfo: : classCCPUInfo ()
{
Cpuname=new char [128].
Temp=new char [128].

Char OEMString [13].
//OEMString=new char [13].
Int iEAXValue iEBXValue, iECXValue iEDXValue;

//for CPU brand:
_asm
{
Mov eax, 0
Cpuid
Mov DWORD PTR OEMString, ebx
Mov DWORD PTR OEMString + 4, edx
Mov DWORD PTR OEMString + 8, ecx
Mov BYTE PTR OEMString + 12, 0
}
Name=new char [15].
Strcpy (Name, OEMString);

//more CPU information:
_asm
{
Mov eax, 1
Cpuid
Mov iEAXValue, eax
Mov iEBXValue, ebx
Mov iECXValue, ecx
Mov iEDXValue, edx
}
MMX=bool (iEDXValue & amp; 0 x800000);
IFamily=(0 xf00 & amp; IEAXValue) & gt;> 8;
FPU=bool (iEDXValue & amp; 0 x1);

//H_DMAT ();//get the CPU information, the slower the
}

ClassCCPUInfo: : ~ classCCPUInfo ()
{
The delete [] Name;
The delete [] cpuname;
The delete [] temp;
//delete [] OEMString;
}

Int classCCPUInfo: : GetSpeed ()
{
Int PriorityClass, Priority;
HANDLE hThread hProcess;

HThread=GetCurrentThread ();
HProcess=GetCurrentProcess ();

PriorityClass=GetPriorityClass (hProcess);
Priority=GetThreadPriority (hThread);

SetPriorityClass (hProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority (hThread THREAD_PRIORITY_TIME_CRITICAL);

Long lEAXValue lEDXValue;

SleepEx (50, false);

_asm
{
Xor eax, eax
RDTSC
Mov lEAXValue, eax
Mov lEDXValue, edx
}

If (SleepEx (500, false)==0)
{
_asm
{
Xor eax, eax
RDTSC
Sub eax, lEAXValue
SBB edx, lEDXValue
Mov lEAXValue, eax
Mov lEDXValue, edx
}
}

SetThreadPriority (hThread, Priority);
SetPriorityClass (hProcess, PriorityClass);
Return lEAXValue/(1000.0 * 500);
}

Bool classCCPUInfo: : withMMX ()
{
Return MMX.
}

Int classCCPUInfo: : GetFamily ()
{
Return iFamily;
}

Int classCCPUInfo: : GetName (char * name)
{
If (name==NULL) return 1;
Strcpy (name, name);
return 0;
}

Int classCCPUInfo: : GetTypeName (char * type)
{
//EAX 8 to 11 showed a few 86:
//3-386
//4 - i486
//5 - Pentium
//6 - Pentium Pro Pentium II
//2 - Dual Processors
If (type==NULL) return 1;
The switch (iFamily)
{
Case 2: strcpy (type, "Dual Processors"); break;
Case 3: strcpy (type, "386"); break;
Case 4: strcpy (type, "486"); break;
Case 5: strcpy (type, "Pentium"); break;
Case 6: strcpy (type, "P2/3, celeron, PPro"); break;
Case: 15 strcpy (type, "P4, P4Celeron"); break;
Default: strcpy (type, "Unknown type");
}
return 0;
}

Bool classCCPUInfo: : hasFPU ()
{
Return FPU.
}

Void classCCPUInfo: : H_DMAT () {//CPU information, the slower the
Memset (cpuname, '\ 0', 128);
Memset (temp, '\ 0', 128);
GetName (cpuname);
C_OPHS=String (cpuname);//CPU name
C_AYUQ=GetSpeed ();//speed
GetTypeName (temp);
C_XLNA=String (temp);//type
C_CFGY=hasFPU ();//HasFPU
C_RBZA=withMMX ();//WithMMX
}

# endif

/*
# include "classCPUInfo. H"//take CPU information
ClassCCPUInfo * F_HEFM;//get the CPU information
Void __fastcall TForm1: : FormCreate (TObject * Sender)
{
F_HEFM=new classCCPUInfo ();//get the CPU information
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Void __fastcall TForm1: : FormClose (TObject * Sender, TCloseAction & amp; The Action)
{
The delete F_HEFM;//get the CPU information
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related