Ask a questionAsk a question
 

Question AccessibleObjectFromPoint

  • Saturday, October 10, 2009 5:57 PMJigs Patel Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Dear All,

    I had small VC++ 6.0 MFC based application which does call a below
    function in timer of 1 second.
    The function gets data under mouse

    Problem:
                I am having memory leakage with this function. if i
    comment out this function calling then there is no leakage.

    -------------------------------------------------------------------------------------------------------------------
    bool CTextUnderMouse::GetTextUnderMouse(CString& sName,CString&
    sValue,CString& sRole,CString& sExeName)
    {
           CPoint CursorPos;
           GetCursorPos(&CursorPos);
           IAccessiblePtr pIAcc;
           _variant_t vt,vtValue;

           if (SUCCEEDED(AccessibleObjectFromPoint (CursorPos,&pIAcc,&vt)))
           {

                   sName.Empty();
                   BSTR pName = NULL;
                   if ( SUCCEEDED( pIAcc->get_accName(vt, &pName)))
                   {
                           if (pName && ::SysStringLen(pName))
                           {
                                   sName = pName;
                           }
                           ::SysFreeString(pName);
                   }

                   vt.Clear();
                   sValue.Empty();
                   BSTR pValue = NULL;
                   if (SUCCEEDED( pIAcc->get_accValue(vtValue,&pValue)))
                   {
                           if (pValue && ::SysStringLen(pValue))
                           {
                                   sValue += pValue;
                           }

                           ::SysFreeString(pValue);
                   }

                   vtValue.Clear();

                   VARIANT vChild;
                   vChild.vt = VT_I4;
                   vChild.lVal = CHILDID_SELF;
                   VARIANT vResult;
                   DWORD dwRoleID;
                   if (SUCCEEDED( pIAcc->get_accRole(vChild,&vResult)))
                   {
                           if (vResult.vt == VT_I4)
                           {
                                   dwRoleID = vResult.lVal;
                                   UINT nRoleLength;
                                   CString sRoleString;
                                   nRoleLength = GetRoleText(dwRoleID,NULL,
    0);
                                   LPTSTR lpszRoleString = (LPTSTR)malloc
    ((nRoleLength + 1) * sizeof
    (TCHAR));
                                   GetRoleText
    (dwRoleID,lpszRoleString,nRoleLength + 1);
                                   sRole = lpszRoleString;
                                   free(lpszRoleString);
                           }
                   }

                   VariantClear(&vResult);

                   VariantClear(&vt);
                   sExeName.Empty();
                   HWND hWnd = NULL;
                   if ((hWnd = WindowFromPoint(CursorPos)) != NULL)
                   {
                           DWORD dwProcessID,dwThreadID;
                           CWnd* pCurrentWnd = CWnd::FromHandle(hWnd);
                           sExeName = GetWindowModuleName
    (pCurrentWnd,dwProcessID,dwThreadID);
                   }

                                   pIAcc->Release()
                   return true;
           }
           return false;

    }

    ---------------------------------------------------------------------------
    ----------------------------------------

    Do anyone see problem with this code or somthing is missing in it?

    If i keep my application running full day and then at end of day if i observer memory usage in task manager then it shows more memory than i started my program.

    I am not expert in com programming. Please help me to fix this issue.

    Also i used Application verifier but it does not show me any leakage.

     

    I am

    Regards,

    Jignesh