C++, ATL: Access of folder content by index fails

G

Guest

I have a very simple COM-add-in where I try to access a folder.
But the direct access by index fails:

CComPtr<Outlook::_NameSpace> NameSpace;
m_spApp->GetNamespace(L"MAPI", &NameSpace);

CComPtr<Outlook::MAPIFolder> InBoxFolder;
CComPtr<Outlook::MAPIFolder> RootFolder;
NameSpace->GetDefaultFolder(Outlook::blush:lFolderInbox, &InBoxFolder);
InBoxFolder->get_Parent((IDispatch **)&RootFolder);
CComPtr<Outlook::_Folders> Folders;
RootFolder->get_Folders(&Folders);

Outlook::MAPIFolder * pFolder = NULL;
HRESULT hr = Folders->GetFirst(&pFolder);
ATLASSERT(hr == S_OK);
hr = Folders->Item(CComVariant(0), &pFolder);
ATLASSERT(hr == S_OK);

The second ATLASSERT() fails (out of bounds) whereas the first succeeds! Why?
 
D

Dan Mitchell

=?Utf-8?B?Um9u?= said:
Got it. The Item property works not zero based. My god.

This is because people using the OOM are expected to be using VB, which
is 1-based. You should also be careful about assuming that 'true' = 1, and
you'll have to do some casting between string types to get things in/out
of BSTR.

See http://support.microsoft.com/kb/260626/en-us for some sample code,
though they're using #import to get the TLB info so the class names are a
bit different.

-- dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top