📄 tstdll32.c
字号:
/***************************************************************
* C file: Tstdll32.c... for Tstdll32.exe
*
* This program has been developed by Intel Corporation.
* You have Intel's permission to incorporate this code
* into your product, royalty free. Intel has various
* intellectual property rights which it may assert under
* certain circumstances, such as if another manufacturer's
* processor mis-identifies itself as being "GenuineIntel"
* when the CPUID instruction is executed.
*
* Intel specifically disclaims all warranties, express or
* implied, and all liability, including consequential and
* other indirect damages, for the use of this code,
* including liability for infringement of any proprietary
* rights, and including the warranties of merchantability
* and fitness for a particular purpose. Intel does not
* assume any responsibility for any errors which may
* appear in this code nor any responsibility to update it.
*
* * Other brands and names are the property of their respective
* owners.
*
* Copyright (c) 1995, Intel Corporation. All rights reserved.
* History:
* June 12 96: fixed misdeclaration for wincpufeatures() -- now a DWORD
* : added message for MMX(TM) Technology processors
* Aug 96 : added check for missing dll.
*
***************************************************************/
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include "tstdll32.h"
#include "resource.h"
HINSTANCE hLibrary; //handle for cpuinf32 dll
WORD (FAR *lpfnwincpuid)();
WORD (FAR *lpfnwincpuidsupport)();
WORD (FAR *lpfnwincpuidext)();
DWORD (FAR *lpfnwincpufeatures)();
ushort(FAR PASCAL *lpfngetdllversion)();
struct TIME_STAMP (FAR *lpfnwinrdtsc)();
struct FREQ_INFO (FAR *lpfnwincpuspeed)(int BSFclocks);
HWND hWnd;
HDC hDC;
#if !defined (APIENTRY)
#define APIENTRY pascal
#endif
// The name of this application
#define APPCLASSNAME "tstdll32"
HINSTANCE hInst;
char szAppName[] = "tstdll32";
char szAppIconName[] = "test32icon";
char szTitle[] = "32-bit dll test";
char szAppClass[32];
/***************************************************************
* WinMain()
*
* Inputs:
* hInstance Main window handle instance
* hPrevInstance Previous window handle instance
* lpCmdLine Pointer to command line string
* nCmdShow Window display flag
*
* Results:
* return value of the PostQuitMessage function if the function
* is successful.
* return NULL if it terminates before entering the message
* loop.
***************************************************************/
int APIENTRY WinMain ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
char buf[512]=""; // String Variable for
// Message Boxes
//Load CPUINF32.DLL and do CPUID
if (LoadLibrary(CPUINFODLL)==NULL) {
if (LOBYTE(LOWORD(GetVersion()))<4) {
return (FALSE); // if DLL not found exit app
}
else {
sprintf(buf, "CPUINF32.DLL not found");
MessageBox(NULL,buf,"Error", MB_ICONINFORMATION);
return (FALSE); // if DLL not found exit app
}
}//if
else {
sprintf( szAppClass, "%s%d", APPCLASSNAME, hInstance);
if (!InitApplication( hInstance)) {
return (FALSE);
}
// Initialization for specific instance
if (!InitInstance(hInstance, nCmdShow)) {
return (FALSE);
}
EventLoop(hInstance);
return 0;
lpCmdLine;
}
} // WinMain()
/***************************************************************
* InitApplication()
*
* Inputs:
* hInstance Handle for first instance of app
*
* Returns:
* atom that uniquely identifies the class being registered.
* zero if an error occurs.
***************************************************************/
BOOL InitApplication( HINSTANCE hInstance)
{ // called for first instance of app
WNDCLASS wc;
wc.style = (CS_HREDRAW | CS_VREDRAW | CS_OWNDC);
wc.lpfnWndProc = (WNDPROC)WndProc; // Window Procedure
wc.cbClsExtra = 0; // No per-class
// extra data.
wc.cbWndExtra = (int)NULL; // 4-bytes extra
// data.
wc.hInstance = hInstance; // Owner of this
// class
wc.hIcon = LoadIcon (hInstance, szAppIconName);
// Icon name from
// .RC
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
// Cursor
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
// Default color
wc.lpszMenuName = szAppName; // Menu name from
// .RC file
wc.lpszClassName = szAppClass; // Name to register
// as
return (RegisterClass(&wc));
} // InitApplication()
/***************************************************************
* InitInstance()
*
* Purpose:
* Initialization for first instance of app.
*
* Inputs:
* hInstance Main window handle instance
* nCmdShow Main window display flag
*
* Returns:
* Always returns true.
***************************************************************/
BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
{
HWND wHdl;
hInst = hInstance; // Save instance handle
// Main window for this app
// instance.
wHdl = CreateWindow(
szAppClass, // See RegisterClass()
szTitle, // Window title bar
WS_OVERLAPPEDWINDOW, // Window style.
CW_USEDEFAULT, // Init x pos
CW_USEDEFAULT, // Init y pos
CW_USEDEFAULT, // Init x size
CW_USEDEFAULT, // Init y size
NULL, // Overlapped windows have no
// parent.
NULL, // Use the window class menu.
hInstance, // This instance owns this
// window.
NULL // We don't use any data in our
// WM_CREATE
);
// Make the window visible; update its client area;
// and return "success"
ShowWindow(wHdl, nCmdShow); // Show the window
UpdateWindow(wHdl); // Sends WM_PAINT message
hWnd = wHdl; // Used in actions.c
return (TRUE); // We succeeded...
} // InitInstance()
/***************************************************************
* EventLoop()
*
* Inputs:
* hInstance Window instance handle
*
* Returns: none
***************************************************************/
void EventLoop(HINSTANCE hInstance)
{
MSG msg;
HANDLE hAccel;
hAccel=LoadAccelerators(hInstance, szAppName);
while (GetMessage(&msg, // Message structure
NULL, // Handle of window receiving
// the message
0, // Lowest message to examine
0)) // Highest message to examine
{
if (!TranslateAccelerator (hWnd,hAccel, &msg)) {
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
}
} // EventLoop()
void GetSpeed( int iType )
{
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
struct FREQ_INFO cpu_speed; // Return variable
// structure for
// cpuspeed
// routine
char buf[512]=""; // String Variable for
// Message Boxes
int u1,u2,exact; // Statistical variables for
int d1,d2; // raw frequency analysis
float per1,per2,per3; // Statistical Percentages
ulong norm_freq, raw_freq; // Previous Normalized
// Frequency
int missed=0; // Keeps track of whether
// any speeds more than
// 3 MHz from the
// normalized occurred
LARGE_INTEGER start, end; // Variables to delay
ulong time; // determine average
// per test
int i, response; // Variable for processing
// MessageBox responses
hLibrary=LoadLibrary(CPUINFODLL);
(FARPROC) lpfnwincpuspeed =
GetProcAddress(hLibrary,"cpuspeed");
cpu_speed = (*lpfnwincpuspeed)(iType);
if ( cpu_speed.in_cycles == 0 && cpu_speed.ex_ticks == 0 ) {
sprintf(buf,
"This processor cannot be accurately "
"timed with this program.\n The "
"processor is either an Intel Clone "
"or is below 80386 level.");
MessageBox(NULL,buf,"error", MB_ICONINFORMATION );
}
sprintf(buf,
"Clock Cycles: %lu cycles\n"
"Elapsed Time: %luus\n"
"Raw Clock Frequency: %luMHz\n"
"Normalized Frequency: %luMHz",
cpu_speed.in_cycles,
cpu_speed.ex_ticks,
cpu_speed.raw_freq,
cpu_speed.norm_freq);
MessageBox(NULL,buf,"32-bit cpuspeed",
MB_ICONINFORMATION );
if ( iType == -1 ) // If Cmos time, then return because too slow
return;
sprintf(buf,
"Would you like to perform\n"
" a 1000 iteration test?");
response = MessageBox(NULL,buf,"test",
MB_YESNO|MB_ICONQUESTION );
if ( response == IDNO ) {
FreeLibrary(hLibrary);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -