Hallo,
das holen der IMapiSession wird unterstützt.
Ich habe hier ein Beispiel in C++ von CodeProject was funktioniert:
Delphi-Quellcode:
String^ Fabric::GetProfileName(
Object^ mapiObject)
{
// the result returned to the calling method
String^ result = nullptr;
// pointer to IUnknown interface
IUnknown* pUnknown = 0;
// pointer to the MAPI session interface
LPMAPISESSION lpMAPISession = 0;
// pointer to a profilesection interface
LPPROFSECT lpProfileSection = 0;
// pointer to a structure that receives the result from HrGetOneProp
LPSPropValue lpSPropValue = 0;
// if we have no MAPIObject everything is senseless...
if (mapiObject == nullptr)
throw gcnew System::ArgumentNullException ("mapiObject","The MAPIObject must not be null!");
try
{
// retrive the IUnknon Interface from our MAPIObject comming from Outlook.
pUnknown = (IUnknown*)Marshal::GetIUnknownForObject(mapiObject).ToPointer ();
// try to retrieve the IMAPISession interface, if we don't get it, everything else is sensless.
if ( pUnknown->QueryInterface (IID_IMAPISession, (void**)&lpMAPISession) != S_OK)
throw gcnew Exception("QueryInterface failed on IUnknown for IID_IMAPISession");
// use the OpenProfileSection of the MAPISession object to retrieve a pointer to the current profilesection interface
if( lpMAPISession->OpenProfileSection((LPMAPIUID)GLOBAL_PROFILE_SECTION_MAPIUID ,NULL,STGM_READ, &lpProfileSection) != S_OK)
throw gcnew Exception("OpenProfileSection method failed!");
// use the HrGetOneProp method to retrieve the profile name property
// the lpPropValue pointer points to the result value
if (HrGetOneProp(lpProfileSection,PR_PROFILE_NAME_W,&lpSPropValue) != S_OK)
throw gcnew Exception("HrGetOneProp failed for property PR_PROFILE_NAME_W !");
// create a managed string from the unmanaged string.
return gcnew String( lpSPropValue->Value.lpszW );
}
catch (
Exception^ ex)
{
// if an error occures get the MAPI error code
DWORD dw = GetLastError();
// and translate it into a human readable message
if (dw != 0) throw gcnew Exception(GetErrorText(dw),ex);
throw ex;
}
finally
{
// Free buffer allocated by MAPI
if (lpSPropValue != 0) MAPIFreeBuffer(lpSPropValue);
// cleanup all references to MAPI Objects
if (lpProfileSection!=0) lpProfileSection->Release();
if (lpMAPISession!=0) lpMAPISession->Release();
if (pUnknown!=0) pUnknown->Release();
}
}
Das IUnknown kommt auch nach meiner Erkenntnis richtig in Delphi an, zumindest das
Handle stimmt in C# und Delphi
überein. Das QueryInterface liefert den
Mapi Fehler: MAPI_E_CALL_FAILED
In C++ klappt es komischerweise
Gruss Jonny