有关sim卡联系人和短信的操作(wm)

    技术2022-05-11  8

    函数功能:读取sim联系人列表

     SIMPHONEBOOKENTRY ContactOutBuf;  SIMCAPS  simcaps;  BOOL bOpenSim = false; DWORD  dwRecNum = 0;  DWORD dwCurRec = 0;  DWORD dwLocation = 0; HSIM  hSim; memset( &simcaps, 0,sizeof( &simcaps )); memset( &ContactOutBuf, 0,sizeof( &ContactOutBuf )); wstring wstrSimContact; HRESULT hRes = SimInitialize( 0, 0, 0,&hSim );

     if  ( FAILED(hRes) ) {  //ErrorHandle( hRes);//错误类型鉴定  goto END;  }

     hRes = SimGetDevCaps( hSim, SIM_CAPSTYPE_PBINDEXRANGE,&simcaps);

     if ( FAILED( hRes)) {  goto END; }

     dwRecNum = simcaps.dwMaxPBIndex - simcaps.dwMinPBIndex+1;  dwCurRec = simcaps.dwMinPBIndex;

     TCHAR tchBuf[5] = { 0 }; while( dwCurRec <= dwRecNum )  {    hRes = SimReadPhonebookEntry( hSim, SIM_PBSTORAGE_SIM, dwCurRec, &ContactOutBuf);

      if( hRes == S_OK)//If the index is unused   {    wstrSimContact += ContactOutBuf.lpszText;   wstrSimContact += L",";   wstrSimContact += ContactOutBuf.lpszAddress;   wstrSimContact += L",";   wstrSimContact += _ltow( dwCurRec, tchBuf, 10 );   wstrSimContact += L"|";   dwCurRec++;   memset( &ContactOutBuf, 0,sizeof( &ContactOutBuf ));   memset( tchBuf, 0, sizeof( tchBuf));  }  else//联系人已经读完 跳出循环  {   break;  } }

     

     

     

     

    * 功 能 描 述:  -修改指定索引的联系人信息 DWORD iIndex = 0; TCHAR tchIndex[5] = { 0 }; TCHAR tchName[21] = { 0 }; TCHAR tchNum[17] = { 0 }; iIndex = _wtol( tchIndex);

     if ( iIndex < 1) {  return -1; } SIMCAPS simcaps ; BOOL bOpenSim = false; DWORD dwRecNum = 0;  DWORD dwCurRec = 0;  DWORD dwLocation = 0; HRESULT hRet = 0; HSIM hSim; memset( &simcaps, 0, sizeof( &simcaps));

     hRet = SimInitialize( 0, 0, 0,&hSim );

     if  ( FAILED(hRet) ) {  //ErrorHandle( hRes);//错误类型鉴定  goto END;  } SIMPHONEBOOKENTRY ContactOutBuf;  memset( &simcaps, 0,sizeof( &simcaps )); memset( &ContactOutBuf, 0,sizeof( &ContactOutBuf )); ContactOutBuf.cbSize = sizeof(SIMPHONEBOOKENTRY); ContactOutBuf.dwParams = SIM_PARAM_PBE_ALL; ContactOutBuf.dwAddressType = SIM_ADDRTYPE_INTERNATIONAL; ContactOutBuf.dwNumPlan = SIM_NUMPLAN_TELEPHONE;

     wcscpy( ContactOutBuf.lpszText, tchName); wcscpy( ContactOutBuf.lpszAddress, tchNum); //取得访问sim能力 hRet = SimGetDevCaps( hSim, SIM_CAPSTYPE_PBINDEXRANGE,&simcaps);

     if ( FAILED( hRet)) {  return -3; }

     dwRecNum = simcaps.dwMaxPBIndex - simcaps.dwMinPBIndex+1;  dwCurRec = simcaps.dwMinPBIndex;

     if ( iIndex > dwRecNum) {  return -4; }

     hRet =  SimWritePhonebookEntry ( hSim, SIM_PBSTORAGE_SIM, iIndex , &ContactOutBuf) ; END: SimDeinitialize( hSim);

     

    功 能 描 述:  -增加sim卡联系人 int iIndex = 0;  TCHAR tchName[21] = { 0 }; TCHAR tchNum[17] = { 0 };

     

     SIMCAPS simcaps ; BOOL bOpenSim = false; DWORD dwRecNum = 0;  DWORD dwCurRec = 0;  DWORD dwLocation = 0; HRESULT hRet = 0; HSIM hSim; memset( &simcaps, 0, sizeof( &simcaps));

     hRet = SimInitialize( 0, 0, 0,&hSim );

     if  ( FAILED(hRet) ) {  //ErrorHandle( hRes);//错误类型鉴定  goto END;  } SIMPHONEBOOKENTRY ContactOutBuf;  memset( &simcaps, 0,sizeof( &simcaps )); memset( &ContactOutBuf, 0,sizeof( &ContactOutBuf )); ContactOutBuf.cbSize = sizeof(SIMPHONEBOOKENTRY); ContactOutBuf.dwParams = SIM_PARAM_PBE_ALL; ContactOutBuf.dwAddressType = SIM_ADDRTYPE_INTERNATIONAL; ContactOutBuf.dwNumPlan = SIM_NUMPLAN_TELEPHONE;

     wcscpy( ContactOutBuf.lpszText, tchName); wcscpy( ContactOutBuf.lpszAddress, tchNum); //取得访问sim能力 hRet = SimGetDevCaps( hSim, SIM_CAPSTYPE_PBINDEXRANGE,&simcaps);

     if ( FAILED( hRet)) {  return -3; } SIMPHONEBOOKENTRY ContactInBuf; memset( &ContactInBuf, 0, sizeof( &ContactInBuf)); dwRecNum = simcaps.dwMaxPBIndex - simcaps.dwMinPBIndex+1;  dwCurRec = simcaps.dwMinPBIndex;  while( dwCurRec <= dwRecNum ) //往后写 {   hRet = SimReadPhonebookEntry(hSim, dwLocation, dwCurRec, &ContactInBuf);

      if( FAILED( hRet))//该位置没有被使用  {            SimWritePhonebookEntry ( hSim, SIM_PBSTORAGE_SIM, iIndex , &ContactOutBuf) ;  }  else  {   dwCurRec++;  } }

    END: SimDeinitialize( hSim);

     

     功 能 描 述:  -删除指定索引sim卡联系人 DWORD iIndex = 0;

     SIMCAPS simcaps ; BOOL bOpenSim = false; DWORD dwRecNum = 0;  DWORD dwCurRec = 0;  DWORD dwLocation = 0; HRESULT hRet = 0; HSIM hSim; memset( &simcaps, 0, sizeof( &simcaps));

     hRet = SimInitialize( 0, 0, 0,&hSim );

     if  ( FAILED(hRet) ) {  //ErrorHandle( hRes);//错误类型鉴定  goto END;  }  //取得访问sim能力 hRet = SimGetDevCaps( hSim, SIM_CAPSTYPE_PBINDEXRANGE,&simcaps);

     if ( FAILED( hRet)) {  return -3; } SIMPHONEBOOKENTRY ContactInBuf; memset( &ContactInBuf, 0, sizeof( &ContactInBuf)); dwRecNum = simcaps.dwMaxPBIndex - simcaps.dwMinPBIndex+1;   if ( iIndex > dwRecNum || iIndex < 1) {  hRet = -2;  goto END; }

     hRet = SimDeletePhonebookEntry( hSim,SIM_PBSTORAGE_SIM,iIndex );

    END: SimDeinitialize( hSim);

     

    功 能 描 述:  -删除整个sim卡联系人

     SIMCAPS simcaps;  DWORD  dwRecNum = 0;  DWORD  dwCurRec = 0;  DWORD dwLocation = 0; HSIM hSim; memset( &simcaps, 0, sizeof( &simcaps));

     HRESULT hRet = SimInitialize( 0, 0, 0,&hSim );

     if  ( FAILED(hRet) ) {  //ErrorHandle( hRes);//错误类型鉴定  goto END;  }

     //取得访问sim能力 hRet = SimGetDevCaps( hSim, SIM_CAPSTYPE_PBINDEXRANGE,&simcaps);

     if ( FAILED( hRet)) {  goto END; }

     dwRecNum = simcaps.dwMaxPBIndex - simcaps.dwMinPBIndex + 1;  dwCurRec = simcaps.dwMinPBIndex;

     while( dwCurRec <= dwRecNum ) //逐条删除 {     SimDeletePhonebookEntry( hSim,SIM_PBSTORAGE_SIM,dwCurRec);  dwCurRec++;  }

    END: SimDeinitialize( hSim); 

     

     

     

    函数功能:读取保存在sim卡中短信

        DWORD dwUsed = 0;    DWORD dwTotal = 0;    HRESULT hResult = 0;  LPSIMMESSAGE lpSimMessage = NULL; HSIM hSim; HRESULT hRet = SimInitialize( 0, 0, 0,&hSim ); wstring wstrSms;

     if  ( FAILED(hRet) ) {  //ErrorHandle( hRes);//错误类型鉴定  goto END;  }

     /*dwStorage = SIM_SMSSTORAGE_SIM;

     else {  dwStorage = SIM_SMSSTORAGE_BROADCAST; }*/

     hResult  = SimGetSmsStorageStatus( hSim, SIM_SMSSTORAGE_SIM, &dwUsed, &dwTotal);  

     if ( S_OK != hResult)    {     return hResult;    }  

      for( DWORD iIndex = 1;iIndex <= dwTotal; iIndex ++)    {     hResult = SimReadMessage( hSim, SIM_SMSSTORAGE_SIM, iIndex, lpSimMessage);  

      if( hResult != S_OK)     {      //ErrorHandle( hResult);   break;    } 

       }END: SimDeinitialize( hSim); 

     

    功 能 描 述:  -删除sim卡短信

     HRESULT hResult = 0;

     DWORD dwIndex = 0 HSIM hSim; hResult = SimInitialize( 0, 0, 0,&hSim );

     if ( FAILED( hResult)) {  return -2; }

     hResult = SimDeleteMessage( hSim,SIM_SMSSTORAGE_SIM, dwIndex );

     if ( FAILED( hResult))//失败,再删除其他的可能位置 {  hResult = SimDeleteMessage( hSim,SIM_SMSSTORAGE_BROADCAST, dwIndex );

      if ( FAILED( hResult))  {   hResult = SimDeleteMessage( hSim,SIM_NUMSMSSTORAGES, dwIndex );  } }

     SimDeinitialize( hSim); 


    最新回复(0)