如何在Windows Mobile中获得本机的电话号码?

转载 2006年06月25日 19:54:00

 前段时间,有好多朋友问,怎么能够获得本机电话号码。在SIM卡上有一个IMSI (International Mobile Subscriber Identity )Record,但这个不是电话号码。估计在server端,有电话号码与IMSI相对应,具体Record情况可以参考SIM GSM File System规范。
注意:本文内容来自Windows Mobile Team Blog。代码部分经过测试(在上海移动网络,易通卡),未能获取到电话号码,可能是服务商不提供该服务。感兴趣的朋友可以参考一下。
#include "stdafx.h"
#include "windows.h"
#include "tapi.h"
#include "tsp.h"
#pragma comment(lib,"cellcore.lib")

#define EXIT_ON_NULL(_p)     /
    if (_p == NULL)    /
{   /
    hr = E_OUTOFMEMORY; /
    goto FuncExit; /
}

#define EXIT_ON_FALSE(_f)     /
    if (!(_f))    /
{   /
    hr = E_FAIL; /
    goto FuncExit; /
}

#define MAX(i, j)   ((i) > (j) ? (i) : (j))

#define TAPI_API_LOW_VERSION   0x00020000
#define TAPI_API_HIGH_VERSION  0x00020000

#define CAPS_BUFFER_SIZE    512

 

HRESULT SHReadLineAddressCaps(LPTSTR szNumber, UINT cchNumber, PDWORD pdwCallFwdModes, UINT nLineNumber)
{
    HRESULT  hr = E_FAIL;
    LRESULT  lResult = 0;
    HLINEAPP hLineApp;
    DWORD    dwNumDevs;
    DWORD    dwAPIVersion = TAPI_API_HIGH_VERSION;
    LINEINITIALIZEEXPARAMS liep;

    DWORD dwTAPILineDeviceID;
    const DWORD dwAddressID = nLineNumber - 1;

    liep.dwTotalSize = sizeof(liep);
    liep.dwOptions   = LINEINITIALIZEEXOPTION_USEEVENT;

    if (SUCCEEDED(lineInitializeEx(&hLineApp, 0, 0, TEXT("ExTapi_Lib"), &dwNumDevs, &dwAPIVersion, &liep)))
    {

        BYTE* pCapBuf = NULL;
        DWORD dwCapBufSize = CAPS_BUFFER_SIZE;
        LINEEXTENSIONID  LineExtensionID;
        LINEDEVCAPS*     pLineDevCaps = NULL;
        LINEADDRESSCAPS* placAddressCaps = NULL;

        pCapBuf = new BYTE[dwCapBufSize];
        EXIT_ON_NULL(pCapBuf);

        pLineDevCaps = (LINEDEVCAPS*)pCapBuf;
        pLineDevCaps->dwTotalSize = dwCapBufSize;

        // Get TSP Line Device ID
        dwTAPILineDeviceID = 0xffffffff;
        for (DWORD dwCurrentDevID = 0 ; dwCurrentDevID < dwNumDevs ; dwCurrentDevID++)
        {
            if (0 == lineNegotiateAPIVersion(hLineApp, dwCurrentDevID, TAPI_API_LOW_VERSION, TAPI_API_HIGH_VERSION,
                &dwAPIVersion, &LineExtensionID))
            {
                lResult = lineGetDevCaps(hLineApp, dwCurrentDevID, dwAPIVersion, 0, pLineDevCaps);

                if (dwCapBufSize < pLineDevCaps->dwNeededSize)
                {
                    delete[] pCapBuf;
                    dwCapBufSize = pLineDevCaps->dwNeededSize;
                    pCapBuf = new BYTE[dwCapBufSize];
                    EXIT_ON_NULL(pCapBuf);

                    pLineDevCaps = (LINEDEVCAPS*)pCapBuf;
                    pLineDevCaps->dwTotalSize = dwCapBufSize;

                    lResult = lineGetDevCaps(hLineApp, dwCurrentDevID, dwAPIVersion, 0, pLineDevCaps);
                }

                if ((0 == lResult) &&
                    (0 == _tcscmp((TCHAR*)((BYTE*)pLineDevCaps+pLineDevCaps->dwLineNameOffset), CELLTSP_LINENAME_STRING)))
                {
                    dwTAPILineDeviceID = dwCurrentDevID;
                    break;
                }
            }
        }

        placAddressCaps = (LINEADDRESSCAPS*)pCapBuf;
        placAddressCaps->dwTotalSize = dwCapBufSize;

        lResult = lineGetAddressCaps(hLineApp, dwTAPILineDeviceID, dwAddressID, dwAPIVersion, 0, placAddressCaps);

        if (dwCapBufSize < placAddressCaps->dwNeededSize)
        {
            delete[] pCapBuf;
            dwCapBufSize = placAddressCaps->dwNeededSize;
            pCapBuf = new BYTE[dwCapBufSize];
            EXIT_ON_NULL(pCapBuf);

            placAddressCaps = (LINEADDRESSCAPS*)pCapBuf;
            placAddressCaps->dwTotalSize = dwCapBufSize;

            lResult = lineGetAddressCaps(hLineApp, dwTAPILineDeviceID, dwAddressID, dwAPIVersion, 0, placAddressCaps);
        }

        if (0 == lResult)
        {
            if (szNumber)
            {
                szNumber[0] = _T('/0');

                EXIT_ON_FALSE(0 != placAddressCaps->dwAddressSize);

                // A non-zero dwAddressSize means a phone number was found
                ASSERT(0 != placAddressCaps->dwAddressOffset);
                PWCHAR tsAddress = (WCHAR*)(((BYTE*)placAddressCaps)+placAddressCaps->dwAddressOffset);

                StringCchCopy(szNumber, cchNumber, tsAddress);
            }

            // Record the allowed forwarding modes
            if (pdwCallFwdModes)
            {
                *pdwCallFwdModes = placAddressCaps->dwForwardModes;
            }

            hr = S_OK;
        }

        delete[] pCapBuf;
    } // End if ()

FuncExit:
    lineShutdown(hLineApp);

    return hr;
}

 

// szNumber - Out Buffer for the phone number

//cchNumber - size of sznumber in characters

// nLineNumber - which phone line (1 or 2) to get the number for
HRESULT SHGetPhoneNumber(LPTSTR szNumber, UINT cchNumber, UINT nLineNumber)
{
    return SHReadLineAddressCaps(szNumber, cchNumber, NULL, nLineNumber);
}


int WINAPI WinMain( HINSTANCE hInstance,
     HINSTANCE hPrevInstance,
     LPTSTR    lpCmdLine,
     int       nCmdShow)
{
 TCHAR tcNum[MAX_PATH]={0};
 SHGetPhoneNumber(tcNum,MAX_PATH,1);

 MessageBox(NULL,tcNum,_T("Number"),MB_OK);
 
 return 0;
}

相关文章推荐

Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号)

豆沙绿:#ecf5e4 豆沙绿RGB色值:R:236  G:245  B:228 Android开发平台中,可通过TelephonyManager 获取本机号码。   Teleph...

Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号)

Android开发平台中,可通过TelephonyManager获取本机号码。 TelephonyManager phoneMgr=(TelephonyManager)this.getSystemSe...

Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号)

Android开发平台中,可通过TelephonyManager 获取本机号码。   TelephonyManager phoneMgr=(TelephonyManager)this.getS...

Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号)

Android开发平台中,可通过TelephonyManager 获取本机号码。   TelephonyManager phoneMgr=(TelephonyManager)this.get...

Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号)

Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号) Android开发平台中,可通过TelephonyManager 获取本机号码。   ...

Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号)

Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号) Android开发平台中,可通过TelephonyManager获取本机号码。   ...

Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号)

Android开发平台中,可通过TelephonyManager获取本机号码。   TelephonyManager phoneMgr=(TelephonyManager)this.g...

windows mobile 电话拦截

  • 2010-08-26 15:54
  • 127KB
  • 下载

windows mobile 6.5.3 绕过签名机制 添加根证书到系统 获得特权API

1、现在还仍在做windows mobile开发的人几乎很少了,都转到安卓平台,所以相关资料少之又少。 2、关于特权API和普通API的说明,网上很多资料,比如http://www.360d...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)