Menu

#21 GetObject fails under Win32all-153

closed-fixed
nobody
com (105)
5
2003-07-12
2003-05-29
No

GetObject fails to retrieve an instance of an object when
a moniker is used.
For example, when working with WMI the following
will fail :-

>>> import win32com.client
>>> o = win32com.client.GetObject("winmgmts:")
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\site-
packages\win32com\client\__init__.py", line 73, in
GetObject
return Moniker(Pathname, clsctx)
File "C:\Python23\lib\site-
packages\win32com\client\__init__.py", line 88, in
Moniker
moniker, i, bindCtx =
pythoncom.MkParseDisplayName(Pathname)
com_error: (-2147221020, 'Invalid syntax', None, None)

I believe there is a bug in the implementation of
MkParseDisplayName - possible corruption of passed
moniker string.

Discussion

  • Ryan Groe

    Ryan Groe - 2003-06-27

    Logged In: YES
    user_id=773155

    In pywin32\com\win32com\src\PythonCOM.cpp, in the
    function pythoncom_MkParseDisplayName, the variable
    displayName appears to get set to a narrow string (char *)
    even though it's declared as a wide string (WCHAR *). When
    displayName is passed into the function MkParseDisplayName
    (as the second parameter), its type is correct (a wide
    character pointer), but the data it contains is wrong.

    Here's a quick and really dirty fix:
    1. add the following somewhere near the top of
    PythonCOM.cpp:
    #include <comdef.h>
    2. change:
    hr = MkParseDisplayName(pBC, displayName,
    &chEaten, &pmk);
    to:
    hr = MkParseDisplayName(pBC, (wchar_t *)(_bstr_t)
    (char *)displayName, &chEaten, &pmk);

     
  • Mark Hammond

    Mark Hammond - 2003-07-12
    • status: open --> closed-fixed
     
  • Mark Hammond

    Mark Hammond - 2003-07-12

    Logged In: YES
    user_id=14198

    Fixed in 154 and 155.