Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   C++, ATL: Access of folder content by index fails (http://www.outlookbanter.com/outlook-vba/58658-c-atl-access-folder-content.html)

Ron October 10th 07 03:01 PM

C++, ATL: Access of folder content by index fails
 
I have a very simple COM-add-in where I try to access a folder.
But the direct access by index fails:

CComPtrOutlook::_NameSpace NameSpace;
m_spApp-GetNamespace(L"MAPI", &NameSpace);

CComPtrOutlook::MAPIFolder InBoxFolder;
CComPtrOutlook::MAPIFolder RootFolder;
NameSpace-GetDefaultFolder(Outlook::olFolderInbox, &InBoxFolder);
InBoxFolder-get_Parent((IDispatch **)&RootFolder);
CComPtrOutlook::_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?


Ron October 10th 07 03:33 PM

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

Got it. The Item property works not zero based. My god.

Ron.

Dan Mitchell October 10th 07 05:21 PM

C++, ATL: Access of folder content by index fails
 
=?Utf-8?B?Um9u?= wrote in news:930E0516-
:
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


All times are GMT +1. The time now is 02:23 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com