我在调用MAPIInitialize(NULL)的时候返回错误-2147417850(无法在设置线程模式后对其加以更改) ,我把CoInitializeEx去掉后,MAPIInitialize调用正常,但是MAPILogonEx(0, NULL, NULL, 0, (&pSession))调用失败,返回值0x80040111(ClassFactory 无法供应请求的类别)。我调试的机器已安装OUTLOOK。请问以上问题如何解决?// 以下是我的代码,VS2005编译可以通过
#define _WIN32_WINNT 0x0500
//--------------------------------------------------------------------
// file include
//--------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <assert.h>#include <atlbase.h>
#include <mapi.h>
#include <mapiutil.h>
#include <mapidefs.h>#include <objbase.h>#pragma comment(lib, "ole32.lib" )
#pragma comment(lib, "mapi32.lib")
// CHR will goto Error if FAILED(hr)
#define CHR(x) if (FAILED(x)) {hr = x; goto Error;}HRESULT DisplayMessageStores()
{
HRESULT hr;
IMAPITable* ptbl;
IMAPISession* pSession; hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); 
hr = MAPIInitialize(NULL);
hr = MAPILogonEx(0, NULL, NULL, 0, (&pSession));//(LPMAPISESSION*)

SRowSet *prowset = NULL;
SPropValue *pval = NULL;
SizedSPropTagArray(1, spta) = { 1, PR_DISPLAY_NAME }; // Log onto MAPI//TEXT("") CHR(hr); 
// Get the table of accounts
hr = pSession->GetMsgStoresTable(0, &ptbl);
CHR(hr);
// set the columns of the table we will query
hr = ptbl->SetColumns ((SPropTagArray *) &spta, 0);
CHR(hr); while (TRUE)
{
// Free the previous row
FreeProws(prowset);
prowset = NULL;
hr = ptbl->QueryRows(1, 0, &prowset);
if ((hr != S_OK) || (prowset == NULL) || (prowset->cRows == 0))
{
break;
}
assert(prowset->aRow[0].cValues == spta.cValues);
pval = prowset->aRow[0].lpProps;
assert(pval[0].ulPropTag == PR_DISPLAY_NAME);
MessageBox(NULL, pval[0].Value.lpszW, TEXT("Message Store"), MB_OK);
}
pSession->Logoff(0, 0, 0);Error:
FreeProws(prowset);
return hr;
}void main()
{
DisplayMessageStores();
return;
}

解决方案 »

  1.   

    TO: yjgx007我试了一下,前面的问题没有了,但是获取SESSION接口的时候还是同样的错误,请问是什么问题。
      

  2.   

    hr = MAPILogonEx(0, NULL, NULL, MAPI_NEW_SESSION, (&pSession)); 
      

  3.   

    还是同样的返回错误。很奇怪。hr 0x80040111 ClassFactory 无法供应请求的类别  HRESULT
      

  4.   

    还是同样的返回错误。很奇怪。hr 0x80040111 ClassFactory 无法供应请求的类别  HRESULT