tspcall.cpp
上传用户:hcyyun520
上传日期:2019-05-14
资源大小:365k
文件大小:3k
源码类别:

TAPI编程

开发平台:

Visual C++

  1. // tspcall.cpp
  2. #include "pch.h"
  3. #include "tspcall.h"
  4. CtspCall::CtspCall(CtspLine* pLine, HTAPICALL htCall)
  5. :   m_pLine(pLine),
  6.     m_dwCallState(LINECALLSTATE_UNKNOWN),
  7.     m_dwCallStateDetail(0),
  8.     m_htCall(htCall)
  9. {
  10. }
  11. CtspCall::~CtspCall()
  12. {
  13.     Drop();
  14. }
  15. CtspLine* CtspCall::GetLine()
  16. {
  17.     return m_pLine;
  18. }
  19. void CtspCall::Drop()
  20. {
  21.     if( m_dwCallState != LINECALLSTATE_IDLE )
  22.     {
  23.         SetCallState(LINECALLSTATE_IDLE);
  24.         m_pLine->m_nActiveCalls--;
  25.     }
  26. }
  27. void CtspCall::SetCallState(
  28.     DWORD   dwCallState,
  29.     DWORD   dwCallStateDetail)
  30. {
  31.     if( dwCallState != m_dwCallState )
  32.     {
  33.         m_pLine->Event(m_pLine->m_htLine,
  34.                        m_htCall,
  35.                        LINE_CALLSTATE,
  36.                        m_dwCallState = dwCallState,
  37.                        m_dwCallStateDetail = dwCallStateDetail);
  38.     }
  39. }
  40. DWORD CtspCall::GetCallState()
  41. {
  42.     return m_dwCallState;
  43. }
  44. LONG CtspCall::StartDial(
  45.     HINSTANCE               hinst,
  46.     HPROVIDER               hProvider,
  47.     DWORD                   dwRequestID,
  48.     const wchar_t*          pwszAddress,
  49.     const LINEDIALPARAMS&   dp)
  50. {
  51.     // Can't dial if we're already doing something else
  52.     if( (m_dwCallState != LINECALLSTATE_UNKNOWN) &&
  53.         (m_dwCallState != LINECALLSTATE_CONNECTED) )
  54.     {
  55.         return LINEERR_OPERATIONUNAVAIL;
  56.     }
  57.     LONG        tr = 0;
  58.     size_t      cbAddress = wcslen(pwszAddress) + 1;
  59.     size_t      cbData = sizeof(TSPUIDATA) + sizeof(LINEDIALPARAMS) + cbAddress;
  60.     TSPUIDATA*  pData = (TSPUIDATA*)(new BYTE[cbData]);
  61.     if( pData )
  62.     {
  63.         // Data passed back from UI
  64.         pData->dwRequestID = dwRequestID;
  65.         pData->pCall = this;
  66.         // Copy LINEDIALPARAMS for UI
  67.         LINEDIALPARAMS* pdp = (LINEDIALPARAMS*)((BYTE*)pData + sizeof(*pData));
  68.         *pdp = dp;
  69.         // Copy dial string for UI
  70.         char*   pszAddress = (char*)((BYTE*)pData + sizeof(*pData) + sizeof(LINEDIALPARAMS));
  71.         wcstombs(pszAddress, pwszAddress, cbAddress);
  72.         wchar_t pwszFileName[MAX_PATH+1];
  73.         TSPI_providerUIIdentify(pwszFileName);
  74.         TUISPICREATEDIALOGINSTANCEPARAMS    params;
  75.         params.dwRequestID = dwRequestID;
  76.         params.hdDlgInst = (HDRVDIALOGINSTANCE)this;
  77.         params.htDlgInst = 0;   // Set by TAPI
  78.         params.lpszUIDLLName = pwszFileName;
  79.         params.lpParams = (void*)pData;
  80.         params.dwSize = cbData;
  81.         // Send message to UI portion via TUISPI_providerGenericDialog
  82.         m_pLine->Event((HTAPILINE)hProvider, 0, LINE_CREATEDIALOGINSTANCE, (DWORD)&params);
  83.         if( params.htDlgInst )
  84.         {
  85.             m_pLine->m_nActiveCalls++;
  86.         }
  87.         else
  88.         {
  89.             tr = LINEERR_OPERATIONFAILED;
  90.         }
  91.     }
  92.     else
  93.     {
  94.         tr = LINEERR_NOMEM;
  95.     }
  96.     delete[] pData;
  97.     return tr;
  98. }