1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include<initguid.h>
#include <msoeapi.h>
#include <mimeole.h>
INT main()
{
IStoreFolder* pFolder = NULL;
IStoreNamespace* pStore = NULL;
IStream* pStream = NULL;
FOLDERPROPS fprops = {0};
MESSAGEPROPS mprops = {0};
HENUMSTORE hFEnum = NULL;
HENUMSTORE hMEnum = NULL;
// Create an instance of an IStoreNamespace object.
CoCreateInstance(
CLSID_StoreNamespace, // Namespace ClassID
NULL, // Outer unknown that aggregates the new object
CLSCTX_INPROC_SERVER, // a server dll
IID_IStoreNamespace, // interface ID
(LPVOID*)&pStore); // The returned IStoreNamespace object
// Initialize the new Namespace object.
pStore->Initialize(NULL, 0);
// Open the first enumerated folder.
fprops.cbSize = sizeof(fprops);
pStore->GetFirstSubFolder(FOLDERID_ROOT, &fprops, &hFEnum);
pStore->OpenFolder(fprops.dwFolderId, 0, &pFolder);
// If a message exists, ...
if (fprops.cMessage > 0)
{
// ...open the first message in the first folder.
mprops.cbSize = sizeof(mprops);
pStore->GetFirstMessage(0, 0, MESSAGEID_FIRST, &mprops, &hMEnum);
pFolder->OpenMessage(mprops.dwMessageId, IID_IStream, &pStream);
// Print the message content to a stream.
HRESULT hr = S_OK;
char szBuff[100];
ULONG cbRead = 1;
while (hr == S_OK && cbRead > 0)
{
hr = pStream->Read(szBuff, sizeof(szBuff)-1, &cbRead);
if (hr == S_OK)
{
szBuff[cbRead] = NULL;
puts(szBuff);
}
}
}
// Release our IStream object.
pStream->Release();
// Release our IStoreFolder object.
pFolder->Release();
// Release our IStoreNamespace object.
pStore->Release();
return 0;
} |
Partager