記錄一下,今天研究出來的,在 Windows Mobile (應該是在 Pocket PC 2002 以上版本就可以用) 如何對外撥出電話。關鍵在 PhoneMakeCall() 這個 API,廢話不多說,看一下範例程式就知道怎麼寫。

#include <tapi.h>  // For TAPIMAXDESTADDRESSSIZE and TAPIMAXCALLEDPARTYSIZE.#include <phone.h> // For PhoneMakeCall()

void MyDlg::OnBtnMakeCall() {    AfxMessageBox(_T("Press OK to make the call."));

    TCHAR call_party[TAPIMAXCALLEDPARTYSIZE];    GetDlgItemText(        IDC_CALL_PARTY,        call_party,        TAPIMAXCALLEDPARTYSIZE - 1    );

    TCHAR phone_number[TAPIMAXDESTADDRESSSIZE];    GetDlgItemText(        IDC_PHONE_NUMBER,        phone_number,        TAPIMAXDESTADDRESSSIZE - 1    );

    // Fill out phone-make-call-info structure    PHONEMAKECALLINFO pmci;    memset(&pmci, 0, sizeof(pmci));    pmci.cbSize         = sizeof(pmci);             // Size of the structure    pmci.dwFlags        = PMCF_PROMPTBEFORECALLING; // Or PMCF_DEFAULT to not                                                    // be prompted to confirm                                                    // the phone call before                                                    // the call is placed.     pmci.pszDestAddress = phone_number;             // phone #    pmci.pszAppName     = NULL;                     // Must be NULL    pmci.pszCalledParty = call_party;               // Call party name that                                                    // showed on top of phone #    pmci.pszComment     = NULL;                     // Must be NULL

    // Do the phone call.    if (PhoneMakeCall(&pmci) == 0) {        AfxMessageBox(_T("Successfully made the call."));    }    else {        // Non-zero: PhoneMakeCall() failed.        AfxMessageBox(_T("Failed to make the call."));    }}

不過這程式在 Pocket PC 2003 Emulator 上跑會跑不起來,應該是沒有電話功能的緣故。希望 Smartphone Emulator (還沒抓到) 可以測試,要不然 debug 會很辛苦。

又,其實下面這兩行不太對:

pmci.pszDestAddress = phone_number;pmci.pszCalledParty = call_party;

因為 PHONEMAKECALLINFO.pszDestAddressPHONEMAKECALLINFO.pszCalledParty 其實是 wchar_t*,而不是 TCHAR*,雖然說目前 WinCE 一律都是用 Unicode 所以不會有問題,但難保未來不會改變。