注意,只有是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;
}
本文介绍了一个用于从ThinkPad电脑的Sensor.DLL文件中读取重力感应数据的C++示例程序。该程序展示了如何加载DLL库、获取加速计数据,并通过控制台输出最新零重力加速度值。
2626

被折叠的 条评论
为什么被折叠?



