UUID 机器的全球唯一吗
IMEI:与每台手机一一对应,而且该码是全世界唯一的,读写于手机内存中。它也是该手机在厂家的"档案"和"身份证号"。 由15位数字组成
/******************************************\ //sylar //2010.4.22 PM 2:59:31 //cug@live.cn //get IMEI in windows mobile // come from net. *************************/ #pragma comment(lib, "cellcore.lib") #include <tapi.h> #include <extapi.h> #define CELLTSP_LINENAME_STRING (L"Cellular Line") #define TAPI_API_LOW_VERSION 0x00010003 #define TAPI_CURRENT_VERSION 0x00020000 #define EXT_API_LOW_VERSION 0x00010000 #define EXT_API_HIGH_VERSION 0x00010000 int GetDeviceIMEI( char *StrIMEI) { LINEINITIALIZEEXPARAMS LineExtParams; HLINEAPP hLineApp; HLINE hLine; DWORD dwNumDevs, dwTSPILineDeviceID_DD, dwAPIVersion, dwExtVersion; LINEGENERALINFO lviGeneralInfo; LPLINEGENERALINFO plviGeneralInfo; LPBYTE pLineGeneralInfoBytes = NULL; LONG lRes = -1; int length =1; LineExtParams.dwTotalSize = sizeof(LineExtParams); LineExtParams.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT; dwAPIVersion = TAPI_CURRENT_VERSION; if (lineInitializeEx(&hLineApp, 0, 0, _T("Developer.com Test"), &dwNumDevs, &dwAPIVersion, &LineExtParams)) return -1; dwTSPILineDeviceID_DD = GetLineDeviceID(CELLTSP_LINENAME_STRING, hLineApp, dwAPIVersion, dwNumDevs); if ( dwTSPILineDeviceID_DD == (DWORD)-1 ){ goto exit; } // open the line if( lineOpen(hLineApp, dwTSPILineDeviceID_DD, &hLine, dwAPIVersion, 0, 0, LINECALLPRIVILEGE_OWNER, LINEMEDIAMODE_DATAMODEM, 0) ){ goto exit; } // set up ExTAPI if ( lineNegotiateExtVersion(hLineApp, dwTSPILineDeviceID_DD, dwAPIVersion, EXT_API_LOW_VERSION, EXT_API_HIGH_VERSION, &dwExtVersion) ){ goto exit; } lviGeneralInfo.dwTotalSize = sizeof(lviGeneralInfo); lRes = lineGetGeneralInfo(hLine, &lviGeneralInfo); if (lRes != 0 && lRes != LINEERR_STRUCTURETOOSMALL){ goto exit; } // get IMEI infomation pLineGeneralInfoBytes = (BYTE*)malloc(lviGeneralInfo.dwNeededSize*sizeof(BYTE)); if(pLineGeneralInfoBytes == NULL) goto exit; plviGeneralInfo = (LPLINEGENERALINFO)pLineGeneralInfoBytes; plviGeneralInfo->dwTotalSize = lviGeneralInfo.dwNeededSize; if((lRes = lineGetGeneralInfo(hLine, plviGeneralInfo)) != 0 ){ goto exit; } else{ //--IMEI号,设备唯一标识 LPTSTR tsSerialNumber; length = plviGeneralInfo->dwSerialNumberSize; if(length) tsSerialNumber = (WCHAR*)(((BYTE*)plviGeneralInfo)+plviGeneralInfo->dwSerialNumberOffset); else{ tsSerialNumber = L"Unavailable"; } // conver the wide char to sign char wtoa( (short*)tsSerialNumber, StrIMEI, length); } lRes = strlen(StrIMEI); //out_imei这就是获得的IMEI,unicode表示 exit: if( hLine ) lineClose(hLine); if( hLineApp ) lineShutdown(hLineApp); if( pLineGeneralInfoBytes ) free(pLineGeneralInfoBytes); return lRes; return -1; } static DWORD GetLineDeviceID(const TCHAR* const psTSPLineName, HLINEAPP hLineApp, DWORD dwAPIVersion, DWORD dwNumDevs) { DWORD dwReturn =-1, dwCurrentDevID =0; for(dwCurrentDevID = 0 ; dwCurrentDevID < dwNumDevs; dwCurrentDevID++) { LINEEXTENSIONID LineExtensionID; if( lineNegotiateAPIVersion(hLineApp, dwCurrentDevID, TAPI_API_LOW_VERSION, TAPI_CURRENT_VERSION, &dwAPIVersion, &LineExtensionID) == 0 ) { LINEDEVCAPS LineDevCaps; LineDevCaps.dwTotalSize = sizeof(LineDevCaps); if( lineGetDevCaps(hLineApp, dwCurrentDevID, dwAPIVersion, 0, &LineDevCaps) == 0 ) { BYTE* pLineDevCapsBytes = (BYTE*)malloc(LineDevCaps.dwNeededSize*sizeof(BYTE)); if(pLineDevCapsBytes != NULL) { LINEDEVCAPS* pLineDevCaps = (LINEDEVCAPS*)pLineDevCapsBytes; pLineDevCaps->dwTotalSize = LineDevCaps.dwNeededSize; if( lineGetDevCaps(hLineApp, dwCurrentDevID, dwAPIVersion, 0, pLineDevCaps) == 0 ) { if(0 == _tcscmp((TCHAR*)((BYTE*)pLineDevCaps+pLineDevCaps->dwLineNameOffset),psTSPLineName)) dwReturn = dwCurrentDevID; } free(pLineDevCapsBytes); } } } } return dwReturn; } /******************************************\ //sylar //2010.4.22 PM 2:59:31 //cug@live.cn //QQ67666938 //open backlight in windows mobile *************************/ // open reg lResult=RegOpenKeyEx(HKEY_CURRENT_USER,L"ControlPanel\\Backlight",0,0,&hOpenKey); if( RegQueryValueEx(hOpenKey,L"BatteryTimeoutUnchecked",NULL,&type,(BYTE*)&dwBatValue,&lenght)==ERROR_SUCCESS ) { RegSetValueEx(hOpenKey,L"BatteryTimeout",0,type,(BYTE*)&dwBatValue,lenght); RegSetValueEx(hOpenKey,L"BatteryTimeoutUnchecked",0,type,(BYTE*)&dwKeyValue,lenght); } if( RegQueryValueEx(hOpenKey,L"ACTimeoutUnchecked",NULL,&type,(BYTE*)&dwAcValue,&lenght) == ERROR_SUCCESS ) { RegSetValueEx(hOpenKey,L"ACTimeout",0,type,(BYTE*)&dwAcValue,lenght); RegSetValueEx(hOpenKey,L"ACTimeoutUnchecked",0,type,(BYTE*)&dwKeyValue,lenght); } /******************************************\ //sylar //2010.4.22 PM 2:59:31 //cug@live.cn //QQ67666938 //get power status in windows mobile *************************/ SYSTEM_POWER_STATUS_EX status; GetSystemPowerStatusEx( &status, TRUE ); /******************************************\ //sylar //2010.4.22 PM 2:59:31 //cug@live.cn //QQ67666938 //get UUID (17byte) in windows mobile .. UUID in OutUUID *************************/ int DEV_GetDeviceUUID( char *OutUUID ) { DWORD dwOutBytes, i, len, nBuffSize = 256; unsigned char arrOutBuff[256], temp[64], strDeviceInfo[256]; KernelIoControl(IOCTL_HAL_GET_DEVICEID, 0, 0, arrOutBuff, nBuffSize, &dwOutBytes); memset( strDeviceInfo, '\0', 256 ); for ( i = 0; i<dwOutBytes; i++){ sprintf( temp, "%02X", arrOutBuff[i] ); strcat( strDeviceInfo, temp ); } memset( arrOutBuff, '\0', 256 ); memcpy( arrOutBuff, strDeviceInfo+40, 2 ); memcpy( arrOutBuff+2, strDeviceInfo+45, 9 ); memcpy( arrOutBuff+2+9, strDeviceInfo+70, 6 ); { unsigned short wbuffer[128]; atow( arrOutBuff, wbuffer, 128 ); } len = strlen(arrOutBuff); memcpy( OutUUID, arrOutBuff, len ); return len; } /******************************************\ //sylar //2010.4.22 PM 2:59:31 //cug@live.cn //QQ67666938 //get UUID (17byte) in symbian .. UUID in OutUUID *************************/ CTelephony *iTelephony = CTelephony::NewL(); CleanupStack::PushL(iTelephony); TRequestStatus iStatus; CTelephony::TSubscriberIdV1 iSubscriberId; CTelephony::TSubscriberIdV1Pckg iSubscriberIdPckg(iSubscriberId); iTelephony->GetSubscriberId(iStatus, iSubscriberIdPckg); User::WaitForRequest(iStatus); User::LeaveIfError(iStatus.Int()); TBuf8<50> in_uuid; in_uuid.Copy(iSubscriberIdPckg().iSubscriberId); sprintf(OutUUID, "%s", in_uuid); iTelephony->CancelAsync(CTelephony::EGetSubscriberIdCancel); CleanupStack::PopAndDestroy(iTelephony); return in_uuid.Length(); /******************************************\ //sylar //2010.4.22 PM 2:59:31 //cug@live.cn //QQ67666938 //get IMEI (17byte) in symbian .. IMEI in OutIMEI *************************/ CTelephony* iTelephony = CTelephony::NewL(); CleanupStack::PushL(iTelephony); CTelephony::TPhoneIdV1 iIdV1; CTelephony::TPhoneIdV1Pckg iIdV1Pkg(iIdV1); TRequestStatus iStatus; iTelephony->GetPhoneId(iStatus, iIdV1Pkg); User::WaitForRequest(iStatus); User::LeaveIfError(iStatus.Int()); TBuf8<50> in_imei; in_imei.Copy(iIdV1Pkg().iSerialNumber); sprintf(OutIMEI, "%s", in_imei.Ptr()); iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel); CleanupStack::PopAndDestroy(iTelephony); iStatus.Int();