diff --git a/src/calibre/devices/mtp/windows/device.cpp b/src/calibre/devices/mtp/windows/device.cpp index a8d76959bc..d7f63f7038 100644 --- a/src/calibre/devices/mtp/windows/device.cpp +++ b/src/calibre/devices/mtp/windows/device.cpp @@ -7,10 +7,6 @@ #include "global.h" -extern IPortableDevice* wpd::open_device(const wchar_t *pnp_id, IPortableDeviceValues *client_information); -extern IPortableDeviceValues* wpd::get_client_information(); -extern PyObject* wpd::get_device_information(IPortableDevice *device, IPortableDevicePropertiesBulk **pb); - using namespace wpd; // Device.__init__() {{{ static void @@ -28,8 +24,6 @@ dealloc(Device* self) Py_END_ALLOW_THREADS; } - if (self->client_information != NULL) { self->client_information->Release(); self->client_information = NULL; } - Py_XDECREF(self->device_information); self->device_information = NULL; Py_TYPE(self)->tp_free((PyObject*)self); @@ -48,9 +42,9 @@ init(Device *self, PyObject *args, PyObject *kwds) self->bulk_properties = NULL; - self->client_information = get_client_information(); - if (self->client_information != NULL) { - self->device = open_device(self->pnp_id, self->client_information); + CComPtr client_information = get_client_information(); + if (client_information) { + self->device = open_device(self->pnp_id, client_information); if (self->device != NULL) { self->device_information = get_device_information(self->device, &(self->bulk_properties)); if (self->device_information != NULL) { diff --git a/src/calibre/devices/mtp/windows/device_enumeration.cpp b/src/calibre/devices/mtp/windows/device_enumeration.cpp index 7d9729eb36..dd4435ed25 100644 --- a/src/calibre/devices/mtp/windows/device_enumeration.cpp +++ b/src/calibre/devices/mtp/windows/device_enumeration.cpp @@ -46,7 +46,7 @@ IPortableDeviceValues *get_client_information() { // {{{ return client_information; } // }}} -IPortableDevice *open_device(const wchar_t *pnp_id, IPortableDeviceValues *client_information) { // {{{ +IPortableDevice *open_device(const wchar_t *pnp_id, CComPtr &client_information) { // {{{ IPortableDevice *device = NULL; HRESULT hr; diff --git a/src/calibre/devices/mtp/windows/global.h b/src/calibre/devices/mtp/windows/global.h index 50552a7a0d..8baee04bff 100644 --- a/src/calibre/devices/mtp/windows/global.h +++ b/src/calibre/devices/mtp/windows/global.h @@ -8,6 +8,7 @@ #pragma once #define UNICODE #include +#include #include #include @@ -40,7 +41,6 @@ typedef struct { PyObject_HEAD // Type-specific fields go here. wchar_t *pnp_id; - IPortableDeviceValues *client_information; IPortableDevice *device; PyObject *device_information; IPortableDevicePropertiesBulk *bulk_properties; @@ -55,7 +55,7 @@ PyObject *wchar_to_unicode(const wchar_t *o); int pump_waiting_messages(); extern IPortableDeviceValues* get_client_information(); -extern IPortableDevice* open_device(const wchar_t *pnp_id, IPortableDeviceValues *client_information); +extern IPortableDevice* open_device(const wchar_t *pnp_id, CComPtr &client_information); extern PyObject* get_device_information(IPortableDevice *device, IPortableDevicePropertiesBulk **bulk_properties); extern PyObject* get_filesystem(IPortableDevice *device, const wchar_t *storage_id, IPortableDevicePropertiesBulk *bulk_properties, PyObject *callback); extern PyObject* get_file(IPortableDevice *device, const wchar_t *object_id, PyObject *dest, PyObject *callback); diff --git a/src/calibre/devices/mtp/windows/wpd.cpp b/src/calibre/devices/mtp/windows/wpd.cpp index 0cbca6ce8a..9355e0bfea 100644 --- a/src/calibre/devices/mtp/windows/wpd.cpp +++ b/src/calibre/devices/mtp/windows/wpd.cpp @@ -20,10 +20,6 @@ static int _com_initialized = 0; // Application Info wpd::ClientInfo wpd::client_info = {0}; -extern IPortableDeviceValues* wpd::get_client_information(); -extern IPortableDevice* wpd::open_device(const wchar_t *pnp_id, IPortableDeviceValues *client_information); -extern PyObject* wpd::get_device_information(IPortableDevice *device, IPortableDevicePropertiesBulk **bulk_properties); - // Module startup/shutdown {{{ static PyObject * wpd_init(PyObject *self, PyObject *args) { @@ -135,7 +131,6 @@ wpd_enumerate_devices(PyObject *self, PyObject *args) { static PyObject * wpd_device_info(PyObject *self, PyObject *args) { PyObject *ans = NULL; - IPortableDeviceValues *client_information = NULL; IPortableDevice *device = NULL; ENSURE_WPD(NULL); @@ -144,15 +139,14 @@ wpd_device_info(PyObject *self, PyObject *args) { if (!PyArg_ParseTuple(args, "O&", py_to_wchar_no_none, &pnp_id)) return NULL; if (wcslen(pnp_id.ptr()) < 1) { PyErr_SetString(WPDError, "The PNP id must not be empty."); return NULL; } - client_information = get_client_information(); - if (client_information != NULL) { + CComPtr client_information = get_client_information(); + if (client_information) { device = open_device(pnp_id.ptr(), client_information); if (device != NULL) { ans = get_device_information(device, NULL); } } - if (client_information != NULL) client_information->Release(); if (device != NULL) {device->Close(); device->Release();} return ans; } // }}}