COM error 0x80004003 (Invalid pointer) Access to MS Outlook contacts

I am some ATL code that uses smart COM pointers to iterate through MS Outlook contacts, and on some computer I get a COM error 0x80004003 ('Invalid Pointer') for each contact. The same code works fine on other PCs. The code is as follows:

_ApplicationPtr ptr;
ptr.CreateInstance(CLSID_Application);

_NameSpacePtr ns = ptr->GetNamespace(_T("MAPI"));
MAPIFolderPtr folder = ns->GetDefaultFolder(olFolderContacts);

_ItemsPtr items = folder->Items;
const long count = items->GetCount();

for (long i = 1; i <= count; i++)
{
    try
    {
        _ContactItemPtr contactitem = items->Item(i);
        // The following line throws a 0x80004003 exception on some machines
        ATLTRACE(_T("\tContact name: %s\n"), static_cast<LPCTSTR>(contactitem->FullName));
    }
    catch (const _com_error& e)
    {
        ATLTRACE(_T("%s\n"), e.ErrorMessage());
    }
}

I wonder if there can be other applications / add-ons? Any help would be appreciated.

+3
source share
4 answers

FullName - , GET (, - IDL: get_FullName ([out, retval] BSTR * o_sResult)). .

, contactItem COM-. , ATLTRACE, . , , sprintf("",args...).

, :

ATLTRACE(_T("\tContact name: %s\n"),
_bstr_t(contactitem->FullName)?static_cast<LPCTSTR>(contactitem->FullName):"(Empty)")
+1

: , "FullName" ?

, , COM- .

0

?

ATLTRACE(_T("\tContact name: %s\n"), static_cast<LPCTSTR>(contactitem->GetFullName()));
0

NULL .

FullName ( ) GetFullName() ( ), . . , setXXX getXXX. IDL ( TLB IDL TLB). FullName GetFullName, .

, *.tlh ...

0

Source: https://habr.com/ru/post/1708871/


All Articles