class1.cs

来自「WinCE VC++ 获取PDA的手机号」· CS 代码 · 共 65 行

CS
65
字号
using System;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data;
using OpenNETCF.Tapi;

namespace My_Phone_Number
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		static void Main(string[] args)
		{
			Tapi tapi = new Tapi();
			tapi.Initialize();
			Hashtable DeviceCaps;
			int deviceIDCell = -1;
			DeviceCaps = new Hashtable();
			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();
					string szPhoneNumber = Encoding.Unicode.GetString(ac.Data, ac.dwAddressOffset, ac.dwAddressSize);
					MessageBox.Show("My phone number is: " + szPhoneNumber);
					ac = null;
					deviceIDCell = i;
					break;
				}


			}


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

			tapi.Shutdown();
		
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?