⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tstdll16.c

📁 一个取得 CPU 信息的程序源码 可以获取16位和32位CPU的信息
💻 C
📖 第 1 页 / 共 2 页
字号:
									//   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",0);

				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",0);

				break;
				
		case IDM_CMOSSPEED:

				hLibrary=LoadLibrary(CPUINFODLL);

				(FARPROC) lpfnwincpuspeed = 
						GetProcAddress(hLibrary,"cpuspeed");
				
				cpu_speed = (*lpfnwincpuspeed)(-1);
				
				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 );
					
					FreeLibrary(hLibrary);
					return (0);
				}	 	
					 			    						
				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,"16-bit cpuspeed", 
						MB_ICONINFORMATION );

				FreeLibrary(hLibrary);
				
				break;

		case IDM_CPUSPEED:
				
				hLibrary=LoadLibrary(CPUINFODLL);

				(FARPROC) lpfnwincpuspeed = 
						GetProcAddress(hLibrary,"cpuspeed");
				
				cpu_speed = (*lpfnwincpuspeed)(0);
				
				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 );
					
					FreeLibrary(hLibrary);
					return (0);
				}	 	
					 			    						
				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,"16-bit cpuspeed", 
						MB_ICONINFORMATION );
				
								
				sprintf(buf,
					"Would you like to perform\n"
					"  a 100 iteration test?");
				
				response = MessageBox(NULL,buf,"test", 
						MB_YESNO|MB_ICONQUESTION );
				
				if ( response == IDNO ) {
					
					FreeLibrary(hLibrary);
					return(0);
                    
                }
        
                
				// Testing Code.... Runs 100 times and does 
				//   statistical analysis on the data returned.
				//	   --BEGIN--
				
				prev_freq = cpu_speed.norm_freq;
	
				u2=0;
				u1=0;
				exact=0;
				d1=0;
				d2=0;
				
				start = timeGetTime();	// Get starting time for
										//   the following 100
										//   tests to later
										//   determine average
										//   delay per test.
				
				for ( i = 0; i<100; i++ ) {
                
		    		cpu_speed = (*lpfnwincpuspeed)(0);
						        
			        if ( (int)cpu_speed.norm_freq != 
			        	 (int)prev_freq ) {
			        
			            sprintf(buf,
			            	"Previous Frequency was %lu\n"
			            	"Current Frequency is %lu\n"
					    	"Statistical Information "
					    	"will be incorrect.\n\n"
					    	"Continue?", prev_freq,
					    	cpu_speed.norm_freq);
					    	
					    response = MessageBox(NULL,buf,"error",
					    		MB_ICONQUESTION|MB_YESNO);
					    
					    if ( response == IDNO ) {
					    	
					    	FreeLibrary (hLibrary);
					    	return(0);
					    }
					    
					}
					
					prev_freq = cpu_speed.norm_freq;
					
					switch ( (int)cpu_speed.raw_freq - 
							 (int)cpu_speed.norm_freq ) {
						
						case 0:
							exact++;
							break;
						
						case 1:
							u1++;
							break;
						
						case 2:
							u2++;
							break;
						
						case -1:
							d1++;
							break;
						
						case -2:
							d2++;
							break;
					
						default:
 							sprintf(misses,"%s %02d\t",misses,
									((int)cpu_speed.raw_freq-
									 (int)cpu_speed.norm_freq));
							
							missed = 1; // Set missed flag
							
							if ( strlen ( misses ) >= 240 ) {
										// If queue gets too
										//   large, dump data
								sprintf(buf,
									"The following raw speeds"
									" deviated more than 3 MHz"
									"\nfrom their normalized "
								 	"values:\n\n%s\n\n"
								 	"More Deviations may "
								 	"follow\n Continue?",
								 	misses);
								
								response = MessageBox(NULL,buf,
									"deviations",
									MB_YESNO);
								
								if ( response == IDNO ) {
								
									FreeLibrary(hLibrary);
									return (0);
								}

								misses[0] = '\0'; // Reset queue
								missed = 0;		  //   and flag
							}
					}
				}
				
				FreeLibrary(hLibrary);

				end = timeGetTime();		// Get ending time
				time = (int) (end - start); //   for last 100
				time = time / 100;			//   tests and 
											//   average them.
											
				
				speed = cpu_speed.norm_freq;
                                            
                
                                         	// Calculate 
                                         	//   statistical 
                                         	//   information
				per1 = (float) (float)exact;
				
				per2 = (float) ((float)exact+(float)u1+
							(float)d1);
				
				per3 = (float) ((float)exact+(float)u1+
							(float)u2+(float)d1+(float)d2);

				
				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",
					speed-2,speed-1,speed,speed+1,speed+2,d2,d1,
					exact,u1,u2,per1,per2,per3,(100-per3),
					speed,cpu_speed.raw_freq,time);
				
				MessageBox(NULL,buf,"16-bit cpuspeed",
					MB_ICONINFORMATION );

				if ( missed ) {
					
					sprintf(buf,
						"The following raw speeds deviated more"
						" than 3 MHz\n from their normalized "
						"values:\n%s",misses);
					
					MessageBox(NULL,buf,"deviations",
							MB_ICONINFORMATION);
					}
                
                
				//		--END--
				// Testing Code.... Ran 100 times and did 
				//   statistical analysis on the data returned.
												   
		        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: %.8lx \n on a processor with MMX(TM) technology", features);
				else 
				 sprintf(buf,"Feature Flags: %.8lx",features);		
				/***************************/

				
				MessageBox(NULL,buf,"wincpufeatures",
					MB_ICONINFORMATION);
				FreeLibrary(hLibrary);
				break;

		case IDM_READ:

				hLibrary=LoadLibrary(CPUINFODLL);
				(FARPROC) lpfnwinrdtsc = 
					GetProcAddress(hLibrary,"winrdtsc");
					
				stamp=(*lpfnwinrdtsc)();

				FreeLibrary(hLibrary);
				
				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);
				
				}
		        
				break;
		        
		
		case IDM_GETDLLVERSION:
			
				hLibrary=LoadLibrary(CPUINFODLL);
				(FARPROC) lpfngetdllversion =
					GetProcAddress(hLibrary,"getdllversion");
					
				version = (*lpfngetdllversion)();
				
				FreeLibrary(hLibrary);
								
				major = version >> 8;		// Shift out minor
											//   version.
											
				minor = version - major*256;	// Subtract off
												//   major 
												//   version.
				
				sprintf(buf,"CPUINFO16 DLL Version: %x.%x",
					major,minor);
				
				MessageBox(NULL,buf,"getdllversion",
					MB_ICONINFORMATION);
				
				break;
		}
	}

    default:          // Passes it on if unproccessed
         return (DefWindowProc(hWnd, message, uParam, lParam));
	}

    return (0);

} // WndProc()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -