begin process at 2008 08 20 02:40:09
1 228 657 membres
37 nouveaux aujourd'hui
14 254 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

[.NET COMPACT FRAMEWORK ] OBTENIR LE NUMERO DE TELEPHONE DE LA CARTE SIM


Information sur la source

Description

Ce code est en Csharp ( DotNet ) il utilise une librairie externe dispo ici : http://iow4.net/share/fichier/TapiLib.rar
Il faut l'ajouter en reference.

Source

  • //
  • // Fonction d'exemple modifié
  • //
  • string num()
  • {
  • Tapi tapi = new Tapi();
  • tapi.Initialize();
  • Hashtable DeviceCaps;
  • int deviceIDCell = -1;
  • DeviceCaps = new Hashtable();
  • string szPhoneNumber = "";
  • for( int i = 0; i < tapi.NumDevices; i++ )
  • {
  • LINEDEVCAPS dc = new LINEDEVCAPS(1024);
  • dc.Store();
  • int dwVersion = tapi.NegotiateVersion(i);
  • int ret = NativeTapi.lineGetDevCaps(tapi.hLineApp, i, dwVersion, 0, dc.Data);
  • if ( ret < 0 )
  • continue;
  • if ( (LINEERR)ret == LINEERR.STRUCTURETOOSMALL )
  • {
  • dc.Data = new byte[dc.dwNeededSize];
  • ret = NativeTapi.lineGetDevCaps(tapi.hLineApp, i, dwVersion, 0, dc.Data);
  • }
  • dc.Load();
  • if (dc != null && dc.ProviderName == CellTSP.CELLTSP_PROVIDERINFO_STRING)
  • {
  • LINEADDRESSCAPS ac = new LINEADDRESSCAPS(1024);
  • ac.Store();
  • ret = NativeTapi.lineGetAddressCaps(tapi.hLineApp, i, 0, dwVersion, 0, ac.Data);
  • ac.Load();
  • szPhoneNumber = Encoding.Unicode.GetString(ac.Data, ac.dwAddressOffset, ac.dwAddressSize);
  • ac = null;
  • deviceIDCell = i;
  • break;
  • }
  • }
  • if (deviceIDCell == -1) // Not found
  • MessageBox.Show("Could not find cellular line");
  • tapi.Shutdown();
  • return szPhoneNumber;
  • }
//
// Fonction d'exemple modifié 
//

string num()
{
Tapi tapi = new Tapi();
tapi.Initialize();

Hashtable DeviceCaps;
int deviceIDCell = -1;
DeviceCaps = new Hashtable();
string szPhoneNumber = "";

for( int i = 0; i < tapi.NumDevices; i++ )
{
LINEDEVCAPS dc = new LINEDEVCAPS(1024);
dc.Store();
int dwVersion = tapi.NegotiateVersion(i);
int ret = NativeTapi.lineGetDevCaps(tapi.hLineApp, i, dwVersion, 0, dc.Data);
if ( ret < 0 )
continue;
if ( (LINEERR)ret == LINEERR.STRUCTURETOOSMALL )
{
dc.Data = new byte[dc.dwNeededSize];
ret = NativeTapi.lineGetDevCaps(tapi.hLineApp, i, dwVersion, 0, dc.Data);
}
dc.Load();

if (dc != null && dc.ProviderName == CellTSP.CELLTSP_PROVIDERINFO_STRING)
{
LINEADDRESSCAPS ac = new LINEADDRESSCAPS(1024);
ac.Store();
ret = NativeTapi.lineGetAddressCaps(tapi.hLineApp, i, 0, dwVersion, 0, ac.Data);
ac.Load();
szPhoneNumber = Encoding.Unicode.GetString(ac.Data, ac.dwAddressOffset, ac.dwAddressSize);

ac = null;
deviceIDCell = i;
break;
}


}


if (deviceIDCell == -1) // Not found
MessageBox.Show("Could not find cellular line");

tapi.Shutdown();
return szPhoneNumber;
} 

Conclusion

Pour avoir le numero de telephone il suffit d'appeller la fonction num()
J'espere que ce code poura aider. Les perspectives d'application sont nombreuses ( anti-vol pour portable ... )


J'ai ecrit un article sur ce code : http://www.iow4.net/-net-compact-framework-recuperer-le-numero-de-telephone-de-la-carte-sim
    Aucun commentaire pour le moment.

Ajouter un commentaire

Pub



Appels d'offres

Snippets en rapport

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Boutique

Boutique de goodies CodeS-SourceS