Как зарегестрировать TAPI - событие?
От: Albatross  
Дата: 06.03.02 17:44
Оценка:
Например, вызов на модем.
В MSDN по этому поводу написана какая-то чушь

Register Events
The following code snippets demonstrate implementation of a simple event handler, registration of the main TAPI event interface, setting of the event filter, and registration for call notifications.

Before using this code snippet, you must perform the operations in Initialize TAPI and Select an Address.

Note This snippet does not have the error checking and releases appropriate for real code.

C++ Code Snippets [C++]
//
// Snippet 1: Implement a simple event handler.
//
HRESULT STDMETHODCALLTYPE
CTAPIEventNotification::Event(
TAPI_EVENT TapiEvent,
IDispatch * pEvent
)
{
// AddRef the event so it doesn't go away.
pEvent->AddRef();

// Post a message to our own UI thread.
PostMessage(
ghDlg,
WM_PRIVATETAPIEVENT,
(WPARAM) TapiEvent,
(LPARAM) pEvent
);

return S_OK;
}

//
// Snippet 2: Register the event interface.
//
long gulAdvise; // Globally declared
IConnectionPointContainer * pCPC;
IConnectionPoint * pCP;
IUnknown * gUnk;

// Get the connection point container
// interface pointer from the TAPI object.
gpTapi->QueryInterface(
IID_IConnectionPointContainer,
(void **)&pCPC
);

// Get the ITTAPIEventNOtification interface
// pointer from the container.
pCPC->FindConnectionPoint(
IID_ITTAPIEventNotification,
&pCP
);

pCPC->Release();


pTAPIEventNotification->QueryInterface(
IID_IUnknown,
(void **)&pUnk
);

// Call the advise method to give TAPI
// the IUnknown pointer for the event handler.
pCP->Advise(
pUnk,
(ULONG *)&gulAdvise
);

pCP->Release();


//
// Snippet 3: Set the event filter.
//
// Assume we are interested
// only in call-related events.
gpTapi->put_EventFilter(
TE_CALLNOTIFICATION | TE_CALLSTATE | TE_CALLMEDIA
);

//
// Snippet 4: Register an address with TAPI
// for call notifications. Assume we are interested
// in video and audio calls, and that pAddress
// is a pointer to the ITAddress interface of
// an address that can handle both media types.

long glRegister; // Globally declared

gpTapi->RegisterCallNotifications(
pAddress,
VARIANT_TRUE, // monitor privileges
VARIANT_TRUE, // owner privileges
TAPIMEDIATYPE_AUDIO|TAPIMEDIATYPE_VIDEO,
gulAdvise, // As returned by Advise
&glRegister
);





первые строчки этого — вообще чушь полная...
кроме того, такого класса вообще нет — я имею в виду CTAPIEventNotification


что делать-то?
Re: Как зарегестрировать TAPI - событие?
От: Sergeant Украина www.photomirror.com.ua
Дата: 07.03.02 07:40
Оценка:
Здравствуйте Albatross, Вы писали:

A>Например, вызов на модем.

A>В MSDN по этому поводу написана какая-то чушь

A>Register Events

A>The following code snippets demonstrate implementation of a simple event handler, registration of the main TAPI event interface, setting of the event filter, and registration for call notifications.

A> {......}


A>первые строчки этого — вообще чушь полная...

A>кроме того, такого класса вообще нет — я имею в виду CTAPIEventNotification


A>что делать-то?


Немного непонятно... А что, собссно, надо сделать-то? Задача какая?
Все сообщения от ТАПИ приходят в ейную колбэк-функцию, где и обрабатываются нами по желанию.... Или я чего-то не понимаю в формулировке вопроса?....
Курить я буду, но пить не брошу.
Re: Как зарегестрировать TAPI - событие?
От: dubina  
Дата: 21.12.02 21:32
Оценка:
Здравствуйте, Albatross, Вы писали:

A>Например, вызов на модем.

A>В MSDN по этому поводу написана какая-то чушь

A>Register Events

A>The following code snippets demonstrate implementation of a simple event handler, registration of the main TAPI event interface, setting of the event filter, and registration for call notifications.

A>Before using this code snippet, you must perform the operations in Initialize TAPI and Select an Address.


A>Note This snippet does not have the error checking and releases appropriate for real code.


A>C++ Code Snippets [C++]

A>//
A>// Snippet 1: Implement a simple event handler.
A>//
A>HRESULT STDMETHODCALLTYPE
A>CTAPIEventNotification::Event(
A> TAPI_EVENT TapiEvent,
A> IDispatch * pEvent
A> )
A>{
A> // AddRef the event so it doesn't go away.
A> pEvent->AddRef();

A> // Post a message to our own UI thread.

A> PostMessage(
A> ghDlg,
A> WM_PRIVATETAPIEVENT,
A> (WPARAM) TapiEvent,
A> (LPARAM) pEvent
A> );

A> return S_OK;

A>}

A>//

A>// Snippet 2: Register the event interface.
A>//
A>long gulAdvise; // Globally declared
A>IConnectionPointContainer * pCPC;
A>IConnectionPoint * pCP;
A>IUnknown * gUnk;

A>// Get the connection point container

A>// interface pointer from the TAPI object.
gpTapi->>QueryInterface(
A> IID_IConnectionPointContainer,
A> (void **)&pCPC
A> );

A>// Get the ITTAPIEventNOtification interface

A>// pointer from the container.
pCPC->>FindConnectionPoint(
A> IID_ITTAPIEventNotification,
A> &pCP
A> );

pCPC->>Release();


pTAPIEventNotification->>QueryInterface(
A> IID_IUnknown,
A> (void **)&pUnk
A> );

A>// Call the advise method to give TAPI

A>// the IUnknown pointer for the event handler.
pCP->>Advise(
A> pUnk,
A> (ULONG *)&gulAdvise
A> );

pCP->>Release();


A>//

A>// Snippet 3: Set the event filter.
A>//
A>// Assume we are interested
A>// only in call-related events.
gpTapi->>put_EventFilter(
A> TE_CALLNOTIFICATION | TE_CALLSTATE | TE_CALLMEDIA
A> );

A>//

A>// Snippet 4: Register an address with TAPI
A>// for call notifications. Assume we are interested
A>// in video and audio calls, and that pAddress
A>// is a pointer to the ITAddress interface of
A>// an address that can handle both media types.

A>long glRegister; // Globally declared


gpTapi->>RegisterCallNotifications(
A> pAddress,
A> VARIANT_TRUE, // monitor privileges
A> VARIANT_TRUE, // owner privileges
A> TAPIMEDIATYPE_AUDIO|TAPIMEDIATYPE_VIDEO,
A> gulAdvise, // As returned by Advise
A> &glRegister
A> );

A>


A>


A>первые строчки этого — вообще чушь полная...

A>кроме того, такого класса вообще нет — я имею в виду CTAPIEventNotification

A>

A>что делать-то?

В общем не совсем чушь, если до сих пор не разобрался — сообщи
Re: Как зарегестрировать TAPI - событие?
От: zelyony  
Дата: 22.12.02 06:23
Оценка: 24 (2)
Здравствуйте, Albatross, Вы писали:

....

CTAPIEventNotification — это твой класс, реализующий исходящий интерфейс ITTAPIEventNotifiacation ( о СОМ-объектах что-нить слышал? ). этот класс ( помимо методов IUnknown ) должен реализовать ещё один метод Event( TAPI_EVENT TapiEvent, IDispatch* pEvent), в котором ты и обрабатываешь все события TAPI. почему он здесь такой извращённый? оч просто. пока твой код обрабатывает событие, TAPI не может больше заниматься ничем, оно ждёт окончания обработки тобой события! за время пока ты обрабатываешь событие, могут прийти десятки новых сигналов... наверное это понятно? поэтому, в коде параметры передаются в какой-нить другой поток ( твой, не TAPIшный ) и управление тут же возвращается в TAPI. в принципе, тебе никто не запрещает написать логику обработки событий в самом методе, НО... с модемом то это почти сработает, а вот если у тя железка на 1000 линий, то что? а во второй половине кода ты просто подписываешься на получение этих событий, с ATL будет немного проще, но и так понятно. вот примерная реализация класса CTAPIEventNotification:

#define _WIN32_DCOM
#include <ole2.h>
#include <comdef.h>
#pragma hdrstop

#import "tapi3.dll" raw_dispinterfaces, raw_interfaces_only, raw_native_types 
using namespace TAPI3Lib;

//*************************************************************************************
class CTAPIEventNotification : ITTAPIEventNotification {
public:

    ULONG __stdcall AddRef() { return 2; }
    ULONG __stdcall Release() { return 1; }
    HRESULT __stdcall QueryInterface( REFIID iid, void ** ppvObject) {
        *ppvObject = 0;
        if ((iid!=__uuidof(IUnknown)) && (iid!=__uuidof(ITTAPIEventNotification))) return E_NOINTERFACE;
        *ppvObject = this;
        return S_OK;
    }

    HRESULT __stdcall Event( TAPI_EVENT te, IDispatch* pEvent) {
    // обрабатываешь события
        return S_OK;
    }
};

//*************************************************************************************
void main() {
    HRESULT hres = CoInitializeEx( 0, COINIT_MULTITHREADED );

    CTAPIEventNotification* pTAPIEventNotification = new CTAPIEventNotification();

    // инитиализируем TAPI
    // подписываемся на события
    // и так далее

    CoUninitialize();
}

#pragma comment( lib, "ole32.lib" )
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.