| 189 | } |
| 190 | |
| 191 | BOOL PyCom_InterfaceFromPyObject(PyObject *ob, REFIID iid, LPVOID *ppv, BOOL bNoneOK /* = TRUE */) |
| 192 | { |
| 193 | if ( ob == NULL ) |
| 194 | { |
| 195 | // don't overwrite an error message |
| 196 | if ( !PyErr_Occurred() ) |
| 197 | PyErr_SetString(PyExc_TypeError, "The Python object is NULL and no error occurred"); |
| 198 | return FALSE; |
| 199 | } |
| 200 | if ( ob == Py_None ) |
| 201 | { |
| 202 | if ( bNoneOK ) |
| 203 | { |
| 204 | *ppv = NULL; |
| 205 | return TRUE; |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | PyErr_SetString(PyExc_TypeError, "None is not a valid interface object in this context"); |
| 210 | return FALSE; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | if ( !PyIBase::is_object(ob, &PyIUnknown::type) ) |
| 215 | { |
| 216 | PyErr_Format(PyExc_ValueError, |
| 217 | "argument is not a COM object (got type=%s)", |
| 218 | ob->ob_type->tp_name); |
| 219 | return FALSE; |
| 220 | } |
| 221 | IUnknown *punk = PyIUnknown::GetI(ob); |
| 222 | if ( !punk ) |
| 223 | return FALSE; /* exception was set by GetI() */ |
| 224 | /* note: we don't explicitly hold a reference to punk */ |
| 225 | HRESULT hr; |
| 226 | Py_BEGIN_ALLOW_THREADS |
| 227 | hr = punk->QueryInterface(iid, ppv); |
| 228 | Py_END_ALLOW_THREADS |
| 229 | if ( FAILED(hr) ) |
| 230 | { |
| 231 | PyCom_BuildPyException(hr); |
| 232 | return FALSE; |
| 233 | } |
| 234 | /* note: the QI added a ref for the return value */ |
| 235 | |
| 236 | return TRUE; |
| 237 | } |
| 238 | |
| 239 | HRESULT PyCom_MakeRegisteredGatewayObject(REFIID iid, PyObject *instance, PyGatewayBase *base, void **ppv) |
| 240 | { |
no test coverage detected