#python #tapi #pythoncom
Вопрос:
Я работаю с библиотекой DLL TAPI на Python, пытаясь отслеживать все происходящие события.
Столкнулся с проблемой обработки события ITAddressDeviceSpecificEvent
<win32com.gen_py.Microsoft TAPI 3.0 Type Library.ITAddressDeviceSpecificEvent instance at 0x274862726400>
print(dir(event))
['Address',' CLSID ',' Call ',' _ApplyTypes_ ',' __class__ ',' __delattr__ ',' __dict__ ',' __dir__ ',' __doc__ ',' __eq__ ',' __
format__ ',' __ge__ ',' __getattr__ ',' __getattribute__ ',' __gt__ ',' __hash__ ',' __init__ ',' __init_subclass__ ',' __iter__
',' __le__ ',' __lt__ ',' __module__ ',' __ne__ ',' __new__ ',' __reduce__ ',' __reduce_ex__ ',' __repr__ ',' __setattr__ ',' __s
izeof__ ',' __str__ ',' __subclasshook__ ',' __weakref__ ',' _get_good_object_ ',' _get_good_single_object_ ',' _oleobj_ ',' _p
rop_map_get_ ',' _prop_map_put_ ',' coclass_clsid ',' lParam1 ',' lParam2 ',' lParam3 ']
print(event.__ dict__)
{'_oleobj_': <PyIDispatch at 0x0000003FFFC10C90 with obj at 0x0000003FFC9EEE50>}
При попытке получить доступ к адресу, звоните и lParam (
Я получаю сообщение об ошибке
Адрес
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
Вызов
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147221497), None)
И lParam1,2,3
pywintypes.com_error: (-2147352559, 'Does not support a collection.', None, None)
Как можно извлечь данные из этого события? С другими событиями проблем не возникло.
После импорта dll в delphi я просмотрел содержимое ITAddressDeviceSpecificEvent
// *********************************************************************//
// Interface: ITAddressDeviceSpecificEvent
// Flags: (4352) OleAutomation Dispatchable
// GUID: {3ACB216B-40BD-487A-8672-5CE77BD7E3A3}
// *********************************************************************//
ITAddressDeviceSpecificEvent = interface(IDispatch)
['{3ACB216B-40BD-487A-8672-5CE77BD7E3A3}']
function Get_Address(out ppAddress: ITAddress): HResu< stdcall;
function Get_Call(out ppCall: ITCallInfo): HResu< stdcall;
function Get_lParam1(out pParam1: Integer): HResu< stdcall;
function Get_lParam2(out pParam2: Integer): HResu< stdcall;
function Get_lParam3(out pParam3: Integer): HResu< stdcall;
end;
У кого-нибудь есть опыт работы с чем-то подобным?
UPD:
Я нашел пример на языке Си, но, к сожалению, я ничего в нем не понимаю, можно ли его как-то преобразовать в python?
HRESULT STDMETHODCALLTYPE CMyEventNotification::Event(
TAPI_EVENT TapiEvent,
IDispatch * pEvent
)
{
HRESULT hr = S_OK;
//...
switch (TapiEvent)
{
case TE_ADDRESSDEVSPECIFIC:
{
ITAddressDeviceSpecificEvent* pITADSEvent = NULL;
hr = pEvent->QueryInterface(
IID_ITAddressDeviceSpecificEvent,
(void **)(amp;pITADSEvent) );
// If (hr != S_OK) process the error here...
// Retrieve data received from the TSP.
long lParam1=0;
hr = pITADSEvent->get_lParam1(amp;lParam1);
// If (hr != S_OK) process the error here...
long lParam2=0;
hr = pITADSEvent->get_lParam2(amp;lParam2);
// If (hr != S_OK) process the error here...
long lParam3=0;
hr = pITADSEvent->get_lParam3(amp;lParam3);
// If (hr !=S_OK) process the error here...
// Process the data here.
// ...
pITADSEvent->Release();
break;
}
case TE_PHONEDEVSPECIFIC:
{
ITPhoneDeviceSpecificEvent* pITPhEvent = NULL;
hr = pEvent->QueryInterface(
IID_ITPhoneDeviceSpecificEvent,
(void **)(amp;pITPhEvent) );
// If (hr != S_OK) process the error here...
// Retrieve data received from the TSP.
long lParam1=0;
hr = pITPhEvent->get_lParam1(amp;lParam1);
// If (hr != S_OK) process the error here...
long lParam2=0;
hr = pITPhEvent->get_lParam2(amp;lParam2);
// If (hr != S_OK) process the error here...
long lParam3=0;
hr = pITPhEvent->get_lParam3(amp;lParam3);
// If (hr != S_OK) process the error here...
// Process the data here.
//...
pITPhEvent->Release();
break;
}
//...
} // end of switch
//...
}
Комментарии:
1. Параметры вывода Например, рассмотрим заголовок процедуры:
procedure GetInfo(out Info: SomeRecordType);
При вызове GetInfo необходимо передать ему переменную типа SomeRecordType:var MyRecord: SomeRecordType; ... GetInfo(MyRecord);
Параметры вывода часто используются с моделями распределенных объектов, такими как COM. Кроме того, вы должны использовать параметры out при передаче неинициализированной переменной в функцию или процедуру.
Ответ №1:
Нет никакого решения. pywin32 не может правильно анализировать dll, из-за чего дальнейшая работа с такими событиями невозможна