📄 tstdll32.c
字号:
// Testing Code.... Runs 100 times and does
// statistical analysis on the data returned.
// --BEGIN--
norm_freq = cpu_speed.norm_freq;
raw_freq = cpu_speed.raw_freq;
u2=0;
u1=0;
exact=0;
d1=0;
d2=0;
QueryPerformanceCounter(&start);
for ( i = 0; i<1000; i++ ) {
cpu_speed = (*lpfnwincpuspeed)(iType);
switch ( (int)cpu_speed.norm_freq -
(int)norm_freq ) {
case 0:
exact++;
break;
case 1:
u1++;
break;
case 2:
u2++;
break;
case -1:
d1++;
break;
case -2:
d2++;
break;
default:
missed++; // Set missed flag; deviate more than 3Mhz
}
}
QueryPerformanceCounter(&end);
time = (ulong) (end.LowPart - start.LowPart);
time = time / 1193180;
per1 = (float)((float)exact/10.0);
per2 = (float)((float)(u1+d1)/10.0);
per3 = (float)((float)(u2+d2)/10.0);
sprintf(buf,
"%luMHz\t%luMHz\t%luMHz\t%luMHz\t%luMHz\n"
" %03d\t %03d\t %03d\t %03d\t %03d\t"
"\n\n"
"Exact value \t: %.2f\n"
"Within 1 MHz \t: %.2f\n"
"Within 2 MHz \t: %.2f\n\n"
"Beyond 2 MHz \t: %.2f\n\n"
"-----> Normalized Speed \t= %lu\n"
"-----> Raw Speed \t= %lu\n\n"
" Delay per test = %dms",
norm_freq-2,norm_freq-1,norm_freq,norm_freq+1,norm_freq+2,d2,d1,
exact,u1,u2,per1,per2,per3,0.0,
norm_freq,raw_freq,time);
MessageBox(NULL,buf,"32-bit cpuspeed",
MB_ICONINFORMATION );
// --END--
// Testing Code.... Ran 100 times and did
// statistical analysis on the data returned.
FreeLibrary(hLibrary);
}
/***************************************************************
* WndProc(HWND, UINT, WPARAM, LPARAM)
*
* Purpose:
* Processes messages
*
* Messages:
* WM_COMMAND - application menu (About dialog box)
* WM_DESTROY - destroy window
*
* Inputs:
* hWnd Window Handle
* message Type of Message
* uParam Additional Information
* LParam Additional Information
*
* Returns:
* LRESULT returned by DefWindowProc or 0
***************************************************************/
LRESULT CALLBACK WndProc(
HWND hWnd, // Window handle
UINT message, // Type of message
WPARAM uParam, // Additional information
LPARAM lParam // Additional information
)
{ // Message Handler
PAINTSTRUCT ps;
switch (message) {
case WM_CREATE:
hDC = GetDC( hWnd);
break;
case WM_SIZE:
break ;
case WM_PAINT:
hDC=BeginPaint(hWnd,&ps);
EndPaint(hWnd,&ps);
break;
case WM_CLOSE:
return (DefWindowProc(hWnd,message,uParam,lParam));
break;
case WM_DESTROY: // Message: window being destroyed
PostQuitMessage(0);
break;
case WM_COMMAND: // Message: command from application
// menu
{
WORD cpu_type = 0; // CPU Family variable
WORD extensions = 0; // CPU Extensions variable
DWORD features = 0; // CPU Features variable
ushort version = 0; // CPUINFO DLL Version
int major, minor; // Variables for storing DLL
// version
char buf[512]=""; // String Variable for
// Message Boxes
int missed=0; // Keeps track of whether
// any speeds more than
// 3 MHz from the
// normalized occurred
char misses[256]= ""; // Keeps track of all raw
// speeds more than 3 MHz
// from the normalized
// value
struct TIME_STAMP stamp;
// Variable for 64-bit Time
// Stamp read
int cpuid_support; // Flag to determine whether
// CPUID opcode is
// supported
WORD wmId, wmEvent;
wmId = LOWORD(uParam);
wmEvent = HIWORD(uParam);
switch(LOWORD(uParam)) {
case IDM_EXIT:
SendMessage(hWnd, WM_CLOSE, 0, 0l);
break;
case IDM_CPUID:
hLibrary=LoadLibrary(CPUINFODLL);
(FARPROC) lpfnwincpuid =
GetProcAddress(hLibrary,"wincpuid");
(FARPROC) lpfnwincpuidsupport =
GetProcAddress(hLibrary,
"wincpuidsupport");
cpu_type = (*lpfnwincpuid)();
cpuid_support = (*lpfnwincpuidsupport)();
FreeLibrary(hLibrary);
if ( cpu_type & CLONE_MASK )
sprintf(buf,"Intel Clone CPU Family : %x",
cpu_type);
else if ( cpuid_support )
// Intel processor presence
// can only be verified if
// CPUID opcode is
// supported and the
// GenuineIntel vendor ID
// is read.
sprintf(buf,"Intel CPU Family : %x",
cpu_type);
else
sprintf(buf,"CPU Family : %x", cpu_type);
MessageBox(NULL,buf,"wincpuid",
MB_ICONINFORMATION);
break;
case IDM_CPUID2:
hLibrary=LoadLibrary(CPUINFODLL);
(FARPROC) lpfnwincpuidext =
GetProcAddress(hLibrary,"wincpuidext");
extensions = (*lpfnwincpuidext)();
FreeLibrary(hLibrary);
sprintf(buf,"Type/Family/Model/Stepping: %.4x",
extensions);
MessageBox(NULL,buf,"wincpuidext",
MB_ICONINFORMATION);
break;
case IDM_CMOSSPEED:
{
int response;
response = MessageBox(NULL,"This feature is not supported for NT; do you want to continue?","test",
MB_YESNO|MB_ICONQUESTION );
if ( response == IDYES ) {
GetSpeed( -1 );
}
}
break;
case IDM_CPUSPEED:
GetSpeed( 0 );
break;
case IDM_FEATUREFLAGS:
hLibrary=LoadLibrary(CPUINFODLL);
(FARPROC) lpfnwincpufeatures =
GetProcAddress(hLibrary,
"wincpufeatures");
features = (*lpfnwincpufeatures)();
/*Print extra line in message for MMX(TM) technology processor, ie, features(23)=1*/
if (features & 0x00800000) //then MMX(TM) technology
sprintf(buf,
"Feature Flags: %.8x \n on a processor with MMX(TM) technology", features);
else
sprintf(buf,"Feature Flags: %.8x",features);
/***************************/
MessageBox(NULL,buf,"wincpufeatures",
MB_ICONINFORMATION);
FreeLibrary(hLibrary);
break;
case IDM_READ:
hLibrary=LoadLibrary(CPUINFODLL);
(FARPROC) lpfnwinrdtsc =
GetProcAddress(hLibrary,"winrdtsc");
stamp=(*lpfnwinrdtsc)();
if ( stamp.High != 0 || stamp.Low != 0 ) {
sprintf(buf,"Time Stamp: %08lx %08lx",
stamp.High,stamp.Low);
MessageBox(NULL,buf,"winrdtsc",
MB_ICONINFORMATION);
}
else {
MessageBox(NULL,"Time Stamping not "
"available on this system","error",
MB_ICONINFORMATION);
}
FreeLibrary(hLibrary);
break;
case IDM_GETDLLVERSION:
hLibrary=LoadLibrary(CPUINFODLL);
(FARPROC) lpfngetdllversion =
GetProcAddress(hLibrary,"getdllversion");
version = (*lpfngetdllversion)();
major = version >> 8; // Shift out minor
// version.
minor = version - major*256; // Subtract off
// major
// version.
sprintf(buf,"CPUINFO32 DLL Version: %x.%x",
major,minor);
MessageBox(NULL,buf,"getdllversion",
MB_ICONINFORMATION);
FreeLibrary(hLibrary);
break;
}
}
default: // Passes it on if unproccessed
return (DefWindowProc(hWnd, message, uParam, lParam));
}
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -