Article ID: 188482
Article Last Modified on 8/18/2005
#include <objbase.h>
#include <mapix.h>
#include <mapidefs.h>
#include <mapiguid.h>
#include <edk.h>
#include <edkmdb.h>
HRESULT GetServerName()
{
HRESULT hRes = S_OK; // HRESULT returned by this method
LPPROFADMIN pAdminProfiles = NULL; // Pointer to IProfAdmin object
LPSERVICEADMIN pSvcAdmin = NULL; // Pointer to IServiceAdmin object
LPPROFSECT pGlobalProfSect = NULL; // Pointer to IProfSect object
LPSPropValue pProps = NULL; // Pointer to PropValue
// PR_PROFILE_HOME_SERVER
char szServerName[256]; // String that will contain the server name
// If your app doesn't already initialize the MAPI subsystem,
// do it now.
if ( FAILED ( hRes = MAPIInitialize ( NULL ) ) )
return hRes;
// Get a Profile admin object
if ( FAILED ( hRes = MAPIAdminProfiles ( 0L, &pAdminProfiles ) ) )
goto CleanUp;
// Get a ServiceAdmin object
if ( FAILED ( hRes = pAdminProfiles -> AdminServices (
"<profile name>",
NULL,
0L, // Your app's window handle
0L,
&pSvcAdmin ) ) )
goto CleanUp;
// Get the Global Profile Section by calling
// IServiceAdmin::OpenProfileSection use pbGlobalProfileSectionGuid
// defined in EDKMDB.H as the entry ID to request
// The default return is an IProfSect interface.
if ( FAILED ( hRes = pSvcAdmin -> OpenProfileSection (
(LPMAPIUID)pbGlobalProfileSectionGuid,
NULL,
0L,
&pGlobalProfSect ) ) )
goto CleanUp;
// Call HrGetOneProp to get PR_PROFILE_HOME_SERVER
if ( FAILED ( hRes = HrGetOneProp ( pGlobalProfSect,
PR_PROFILE_HOME_SERVER,
&pProps ) ) )
goto CleanUp;
// Set Server name pointer to string equal to value returned from
// HrGetOneProp
strcpy ( szServerName, "PR_PROFILE_HOME_SERVER == " );
strcat ( szServerName, pProps -> Value.lpszA );
// Replace window handle param with your application's window handle
MessageBox ( 0L, szServerName, "Exchange Server Name", MB_OK );
CleanUp:
// Free all memory allocated by any MAPI calls
if ( NULL != pAdminProfiles )
pAdminProfiles -> Release ();
if ( NULL != pSvcAdmin )
pSvcAdmin -> Release ( );
if ( NULL != pGlobalProfSect )
pGlobalProfSect -> Release ( );
if ( NULL != pProps )
MAPIFreeBuffer ( &pProps );
pSvcAdmin = NULL;
pGlobalProfSect = NULL;
pProps = NULL;
pAdminProfiles = NULL;
// Return the HRESULT to the calling function
return hRes;
}
NOTE: Be sure to include the following libraries in the link process:
Kernel32.lib, User32.lib, Msvcrt.lib, Mapi32.lib, Edkguid.lib, Edkutils.lib, Edkmapi.lib, Edkdebug.lib.
Additional query words: kbDSupport kbMsg kbEDK kbEDK400 kbEDK500 kbMAPI100 kbMAPI EDKAPI EMAPI
Keywords: kbhowto kbapi kbmsg KB188482