[pywin32-bugs] [ pywin32-Bugs-3521993 ] pythoncom returns wrong object type
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2012-04-27 12:52:11
|
Bugs item #3521993, was opened at 2012-04-27 05:52 Message generated for change (Tracker Item Submitted) made by daveblob You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3521993&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: com Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Dave Blob (daveblob) Assigned to: Nobody/Anonymous (nobody) Summary: pythoncom returns wrong object type Initial Comment: I’m trying to instantiate a 3rd party com object (Bloomberg’s blpapicom2.Session.1), which works fine via: win32com.client.Dispatch (‘blpapicom2.Session.1’) Except for the fact that it returns the interface of another class (IProviderSession instead of ISession). Instantiating the COM object in excel is not problematic - it returns an object with the correct interface. I’ve traced through the C++ code of pywincom, and nothing unusual seems to be happening – I get the right CLSID back from PyWinObject_AsIID (I get {CLSID_Session Class}); When GetTypeInfo and GetTypeAttr are called I get the wrong interface (IProviderSession). Aware that there might be a problem with Bloomberg's COM dll, I wrote my own test in C++ which, I think, makes the calls in the same order as win32com.client.Dispatch: #include "stdafx.h" #include <Objbase.h> int _tmain(int argc, _TCHAR* argv[]) { CLSID clsid; CLSID iid = IID_IUnknown; IUnknown *punk = NULL; IDispatch *result = NULL; ITypeInfo *pti = NULL; TYPEATTR *attr; DWORD dwClsContext = CLSCTX_SERVER; CoInitialize(NULL); LPOLESTR clsName = OLESTR("blpapicom2.Session.1"); HRESULT hr = CLSIDFromString(clsName, &clsid); SCODE sc = CoCreateInstance(clsid, punk, dwClsContext, iid, (void **)&result); SCODE sc2 = ((IDispatch *)result)->GetTypeInfo(0, LOCALE_USER_DEFAULT, &pti); pti->GetTypeAttr(&attr); return 0; } Run from the debugger, attr contains IID_ISession at the end of the program. Inside my Python script PyITypeInfo::GetTypeAttr attr contains IProviderSession. Fearful that something could be happening between python calls, I modified pythoncom_CoCreateInstance to contain: /* BLOB */ ITypeInfo *pti = NULL; SCODE sc2 = ((IDispatch *)result)->GetTypeInfo(0, LOCALE_USER_DEFAULT, &pti); TYPEATTR *attr; pti->GetTypeAttr(&attr); before the final return and attr still incorrectly contains IID_IProviderSession. I've tried this with my current version of Python (2.6.4), a newer one (2.6.8) as well the current release (2.7.3); All are 32bit versions. I'm using Windows 7 64bit. I think all versions as well as my test case were compiled with the 6.0A version of the windows SDK (though I do have 7.0 installed as well). I have an old windows XP machine and it exhibits the same problem (it is running Python 2.6.2), so I don’t think this is a 32/64 bit problem. Instantiating by GUID has the same problem. As an aside, I downloaded OLEViewer and that the Session class is implemented as dual - could this be affecting things? Even so, I'm still confused as to why Excel and my sample code work and pythoncom does not... ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3521993&group_id=78018 |