⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cedialer.c

📁 Cellcore. ExTAPI,ExTAPIAsync,SMS,TAPI
💻 C
📖 第 1 页 / 共 4 页
字号:
        case LINE_GENERATE:
        case LINE_MONITORDIGITS:
        case LINE_MONITORMEDIA:
        case LINE_MONITORTONE:
        case LINE_REMOVE:
        case LINE_REQUEST:
        default:
            break;
  }
  
}

/***********************************************************************

FUNCTION: 
DialingProc

PURPOSE: 
Processes messages sent to the IDD_DIALING dialog box window. 
    
***********************************************************************/
BOOL CALLBACK DialingProc(
    HWND hwnd, 
    UINT uMsg, 
    WPARAM wParam, 
    LPARAM lParam
    )
{
    SHINITDLGINFO shidi;
    
    switch (uMsg)
    {
    case WM_INITDIALOG:
        
        // Set the global handle to the window.
        g_hwndDial = hwnd; 
        
        // Create OK button in navigation bar.
        shidi.dwMask  = SHIDIM_FLAGS;
        shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | 
            SHIDIF_SIZEDLGFULLSCREEN;
        shidi.hDlg =  hwnd;
        SHInitDialog(&shidi);
        
        // Display the current dialing phone number.
        SetDlgItemText (hwnd, IDC_PHONENUM, g_szCurrentNum); 
        
        break;
        
    case WM_COMMAND:
        
        switch (LOWORD(wParam))
        {
            // Drop the line, close the line, and then close the dialog box.
            // This is the case when the Hangup button gets pushed or
            // when application sends a message to close the dialog box.
        case IDCANCEL:        
        case IDOK:
            
            // Close the current phone line.
            CurrentLineClose ();
            
            // Close the dialing dialog box.
            EndDialog (g_hwndDial, TRUE);
            
            // Invalidate the dialing dialog box window handle.
            g_hwndDial = NULL;
            
            return TRUE;
        }
        break;
    }
    return FALSE;
}
      
/***********************************************************************
      
FUNCTION: 
CurrentLineClose

PURPOSE: 
This function closes the opened line device.  
          
***********************************************************************/
VOID CurrentLineClose ()
{
    Sleep(2000); // Time delay to provide message display.
    
    // If lineMakeCall succeeded, then drop the call.
    if (g_hCall)
    {
        g_DropCallRequestID = lineDrop (g_hCall, NULL, 0);
        Sleep(5000);
        lineDeallocateCall (g_hCall); // Deallocate call handle.
    }
    
    // Close the current line.
    if (g_CurrentLineInfo.hLine)
        lineClose (g_CurrentLineInfo.hLine);
    
    // Reinitialize the variables.
    g_CurrentLineInfo.hLine = NULL;
    g_bCurrentLineAvail = TRUE;
    g_hCall = NULL;
}
      
      
/***********************************************************************
      
FUNCTION: 
GetLineInfo 

PURPOSE:
Get line information for selected line.
    
***********************************************************************/
DWORD GetLineInfo(
    DWORD dwLineID, 
    LPLINEINFO lpLineInfo
    )
{
    DWORD dwSize;
    DWORD     dwReturn;
    LPTSTR lpszLineName = NULL; 
    LPLINEDEVCAPS lpLineDevCaps = NULL;
    
    // Negotiate the API version number. If it fails, return to dwReturn.
    if (dwReturn = lineNegotiateAPIVersion (
        g_hLineApp,                   // TAPI registration handle
        dwLineID,                     // Line device to be queried
        TAPI_VERSION_1_0,             // Least recent API version 
        TAPI_CURRENT_VERSION,         // Most recent API version 
        &(lpLineInfo->dwAPIVersion),  // Negotiated API version 
        NULL))                        // Must be NULL; the provider-
        // specific extension is not 
        // supported on Windows CE
    {
        goto exit;
    }
    
    dwSize = sizeof (LINEDEVCAPS);
    
    // Allocate enough memory for lpLineDevCaps.
    do
    {
        if (!(lpLineDevCaps = (LPLINEDEVCAPS) LocalAlloc (LPTR, dwSize)))
        {
            dwReturn = LINEERR_NOMEM;
            goto exit;
        }
        
        lpLineDevCaps->dwTotalSize = dwSize;
        
        if (dwReturn = lineGetDevCaps (g_hLineApp,
            dwLineID,
            lpLineInfo->dwAPIVersion,
            0,
            lpLineDevCaps))
        {
            goto exit;
        }
        
        // Stop if the allocated memory is equal to or greater than the 
        // needed memory.
        if (lpLineDevCaps->dwNeededSize <= lpLineDevCaps->dwTotalSize)
            break;  
        
        dwSize = lpLineDevCaps->dwNeededSize;
        LocalFree (lpLineDevCaps);
        lpLineDevCaps = NULL;
        
    } while (TRUE);
    
    // Store the line information in *lpLineInfo.
    lpLineInfo->dwPermanentLineID = lpLineDevCaps->dwPermanentLineID;
    lpLineInfo->dwNumOfAddress = lpLineDevCaps->dwNumAddresses;
    lpLineInfo->bVoiceLine = 
        (lpLineDevCaps->dwMediaModes & LINEMEDIAMODE_INTERACTIVEVOICE);
    
    // Allocate memory for lpszLineName.
    if (!(lpszLineName = (LPTSTR) LocalAlloc (LPTR, REASONABLE_BUFFER_SIZE)))
    {
        dwReturn = LINEERR_NOMEM;
        goto exit;
    }  
    
    // Store the line name in *lpszLineName.
    if (lpLineDevCaps->dwLineNameSize > 0)
    {
        StringCbCopy(
            lpszLineName, 
            REASONABLE_BUFFER_SIZE,
            (LPTSTR)((LPSTR)lpLineDevCaps + lpLineDevCaps->dwLineNameOffset));
    }
    else 
    {
        _stprintf (lpszLineName, TEXT("Line %d"), dwLineID);
    }
    
    // Copy lpszLineName to lpLineInfo->lpszLineName.
    lstrcpy (lpLineInfo->szLineName, lpszLineName);
    
    dwReturn = ERR_NONE;
    
exit:
    
    if (lpLineDevCaps)
        LocalFree (lpLineDevCaps);
    
    if (lpszLineName)
        LocalFree (lpszLineName);
    
    return dwReturn; 
}
      
/***********************************************************************
      
FUNCTION: 
InitializeTAPI 

PURPOSE:  
Initialize the application's use of Tapi.dll.
          
***********************************************************************/
DWORD InitializeTAPI ()
{
    DWORD dwLineID,
        dwReturn,
        dwTimeCount = GetTickCount ();
    
    TCHAR szWarning[] = TEXT("Cannot initialize tapi.dll.") 
        TEXT("\nQuit all other telephony")
        TEXT("\nprograms, and try again.");
    
    // Initialize the application's use of Tapi.dll. Keep trying until the
    // user cancels or stops getting LINEERR_REINIT.
    while ( (dwReturn = lineInitialize (&g_hLineApp, 
        g_hInst, 
        (LINECALLBACK) lineCallbackFunc, 
        g_szAppName, 
        &g_dwNumDevs)) == LINEERR_REINIT)
    {
        // Bring up the message box if 5 seconds have passed.
        if (GetTickCount () > 5000 + dwTimeCount)
        {
            if (MessageBox (g_hwndMain, szWarning, TEXT("Warning"), 
                MB_OKCANCEL) == IDOK)
                break;
            
            // Reset the time counter.
            dwTimeCount = GetTickCount ();      
        }  
    }
    
    // If function "lineInitialize" fails, then return.
    if (dwReturn)
        return dwReturn;
    
    // If there is no device, then return.
    if (g_dwNumDevs == 0)
    {
        ErrorBox (TEXT("There are no line devices available."));
        return LINEERR_NODEVICE;
    }
    
    // Allocate buffer for storing LINEINFO for all the available lines.
    if (! (g_lpLineInfo = (LPLINEINFO) LocalAlloc (
        LPTR, 
        sizeof (LINEINFO) * g_dwNumDevs)))
    {
        return LINEERR_NOMEM;
    }
    
    // Fill lpLineInfo[] for every line.
    for (dwLineID = 0; dwLineID < g_dwNumDevs; ++dwLineID)
    {  
        GetLineInfo (dwLineID, &g_lpLineInfo [dwLineID]);
    }
    
    return ERR_NONE;
}

            
/***********************************************************************
            
FUNCTION: 
MakePhoneCall 

PURPOSE:   
Demonstrates the use of lineOpen, lineTranslateAddress, lineMakeCall.
                
***********************************************************************/
VOID MakePhoneCall (LPCTSTR lpszPhoneNum)
{
    DWORD dwReturn,
    dwSizeOfTransOut = sizeof (LINETRANSLATEOUTPUT),
    dwSizeOfCallParams = sizeof (LINECALLPARAMS);
    
    LPLINECALLPARAMS lpCallParams = NULL;
    LPLINETRANSLATEOUTPUT lpTransOutput = NULL;
    
    TCHAR szDialablePhoneNum[TAPIMAXDESTADDRESSSIZE + 1] = {'\0'};
    int err = 0;
    
    // Initialize g_MakeCallRequestID.
    g_MakeCallRequestID = 0;
    
    // Open the current line.
    if (dwReturn = lineOpen (
        g_hLineApp,                 // Usage handle for TAPI
        g_dwCurrentLineID,          // Cannot use the LINEMAPPER value
        &g_CurrentLineInfo.hLine,   // Line handle
        g_CurrentLineInfo.dwAPIVersion, 
        // API version number
        0,                          // Must set to zero for Windows CE
        0,                          // No data passed back 
        LINECALLPRIVILEGE_NONE,     // Can only make an outgoing call
        0,                          // Media mode 
        NULL))                      // Must set to NULL for Windows CE
    {
        goto exit;
    }
    
    // Call translate address before dialing.
    do
    {
        // Allocate memory for lpTransOutput.
        if (!(lpTransOutput = (LPLINETRANSLATEOUTPUT) LocalAlloc (
            LPTR,  
            dwSizeOfTransOut)))
        {
            goto exit;
        }
        
        lpTransOutput->dwTotalSize = dwSizeOfTransOut;
        
        if (dwReturn = lineTranslateAddress (
            g_hLineApp,               // Usage handle for TAPI
            g_dwCurrentLineID,        // Line device identifier 
            g_CurrentLineInfo.dwAPIVersion, 
            // Highest TAPI version supported 
            lpszPhoneNum,             // Address to be translated
            0,                        // Must be 0 for Windows CE
            0,                        // No associated operations 
            lpTransOutput))           // Result of the address translation
        {
            goto exit;
        }
        
        if (lpTransOutput->dwNeededSize <= lpTransOutput->dwTotalSize)
            break; 
        else
        {
            dwSizeOfTransOut = lpTransOutput->dwNeededSize;
            LocalFree (lpTransOutput);
            lpTransOutput = NULL;
        }
        
    } while (TRUE);
    
    dwSizeOfCallParams += lpTransOutput->dwDisplayableStringSize;
    
    if (!(lpCallParams = (LPLINECALLPARAMS) LocalAlloc (
        LPTR, 
        dwSizeOfCallParams)))
    {
        goto exit;
    }

    ZeroMemory(lpCallParams, dwSizeOfCallParams);
    
    // Set the call parameters.
    lpCallParams->dwTotalSize      = dwSizeOfCallParams;
    lpCallParams->dwBearerMode     = LINEBEARERMODE_VOICE;
    lpCallParams->dwMediaMode      = LINEMEDIAMODE_DATAMODEM; 
    lpCallParams->dwCallParamFlags = LINECALLPARAMFLAGS_IDLE;
    lpCallParams->dwAddressMode    = LINEADDRESSMODE_ADDRESSID;
    lpCallParams->dwAddressID      = g_dwCurrentLineAddr;
    lpCallParams->dwDisplayableAddressSize = 
        lpTransOutput->dwDisplayableStringSize;
    lpCallParams->dwDisplayableAddressOffset = sizeof (LINECALLPARAMS);
    
    // Save the translated phone number for dialing.
    lstrcpy (szDialablePhoneNum, 
        (LPTSTR) ((LPBYTE) lpTransOutput + 
        lpTransOutput->dwDialableStringOffset));
    memcpy((LPBYTE) lpCallParams + lpCallParams->dwDisplayableAddressOffset,
        (LPBYTE) lpTransOutput + lpTransOutput->dwDisplayableStringOffset,
        lpTransOutput->dwDisplayableStringSize);

    // Make the phone call. lpCallParams should be NULL if the default 
    // call setup parameters are requested.
    g_MakeCallRequestID = lineMakeCall (g_CurrentLineInfo.hLine,            
        &g_hCall,         
        szDialablePhoneNum, 
        0, 
        lpCallParams);   
    
    
    if (g_MakeCallRequestID > 0) 
    {
        g_bCurrentLineAvail = FALSE;
        
        DialogBox (g_hInst, 
            MAKEINTRESOURCE(IDD_DIALING), 
            g_hwndDialerDlg, 
            (DLGPROC) DialingProc);

⌨️ 快捷键说明

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