thinkpad 使用重力感应编程

来源:互联网 发布:mac ps 添加字体 编辑:程序博客网 时间:2024/04/30 07:41

注意,只有是thinkpad 并支持重力感应,才回有sensor.dll (貌似是)

#include "stdafx.h"
#include <iostream> 
#include "windows.h" 
using namespace std;
typedef void(__stdcall *Print_)(); 
int main(){ 
 int a; 
 HINSTANCE hDll;   //DLL句柄     
 hDll = LoadLibrary("C:/Windows/System32/Sensor.DLL");  
 short cX = 0; 
 short cY = 0; 
 typedef struct  
 {
  int      PresentState;  
  short    LatestRawAccelDataX;  
  short    LatestRawAccelDataY;  
  short    LatestAccelDataX;
  short    LatestAccelDataY;  
  char      Temperature;  
  short    LatestZeroG_X;  
  short    LatestZeroG_Y;  
 } AccelerometerData; 
 typedef void (__stdcall * funcShockproofGetAccelerometerData)( AccelerometerData * ); 
 funcShockproofGetAccelerometerData ShockproofGetAccelerometerData; 
 cin>>a; 
 if (hDll != NULL)    
 {     
  ShockproofGetAccelerometerData = (funcShockproofGetAccelerometerData)GetProcAddress( hDll, "ShockproofGetAccelerometerData" );  
  if( ShockproofGetAccelerometerData )   
  {   
   AccelerometerData ad = { 0 };   
   ShockproofGetAccelerometerData( &ad );   
   cX = ad.LatestZeroG_X;   
   cY = ad.LatestZeroG_Y;   
   cout<<cX<<","<<cY;   
  }    
 } else {  
  cout<<"hDll is null"<<endl;  
 } 
 return 0;   
}

原创粉丝点击