Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

MapiLogonEx function failing

$
0
0

I am using the MAPI IProfAdmin interface for creating the profile .I can see that profile is completely created in registry also .
After that i want to logon using that mapi profile .
For that i am using the MAPILogonEx function without MAPI_LOGON_UI parameter as i dont want any UI there .
At this time logon is failing .I was thinking that profile is not created so what i did ,i used MAPI_LOGON_UI parameter and specified that mapi profile name also .

MAPILogonEx(0,lpszProfile,  NULL,    MAPI_EXTENDED | MAPI_NEW_SESSION | MAPI_UNICODE | MAPI_LOGON_UI, &m_mapiSession)

Now its prompting as invalid name .Then clicking on ok ,it displayed a drop down with a list of existing mapi profile name .I can see my mapi profile there also .I means mapi profile exist but the way i am trying to access is not correct .

Need help on the same .

Here is the code :-

bool CreateProfileWithIProfAdmin(char * szMailbox, char * szServer)
// CreateProfileWithIProfAdmin function: This uses the MAPI IProfAdmin to
// programmatically create a profile. No UI is displayed.
{

  HRESULT     hRes = S_OK;      // Result from MAPI calls.
  LPPROFADMIN   lpProfAdmin = NULL;   // Profile Admin object.
  LPSERVICEADMIN lpSvcAdmin = NULL;   // Service Admin object.
  LPMAPITABLE   lpMsgSvcTable = NULL;  // Table to hold services.
  LPSRowSet    lpSvcRows = NULL;    // Rowset to hold results of table query.
  SPropValue   rgval[2];        // Property structure to hold values we want to set.
  SRestriction  sres;          // Restriction structure.
  SPropValue   SvcProps;        // Property structure for restriction.


    char      szProfile[12] = "temp"; // String for profile name.
    int PR_PROFILE_UNRESOLVED_NAME = 1711734814; // &H6607001E
    int PR_PROFILE_UNRESOLVED_SERVER= 1711800350; // &H6608001E
  enum {iSvcName, iSvcUID, cptaSvc};
  SizedSPropTagArray(cptaSvc,sptCols) = { cptaSvc, PR_SERVICE_NAME, PR_SERVICE_UID };
  // Initialize MAPI.
int a;
  if (FAILED(hRes = MAPIInitialize(NULL)))
  {
    cout<<"Error initializing MAPI.";
    goto error;
  }
  // Get an IProfAdmin interface.
  if (FAILED(hRes = MAPIAdminProfiles(0,       // Flags.
                    &lpProfAdmin))) // Pointer to new IProfAdmin.
  {
    cout<<"Error getting IProfAdmin interface.";
    goto error;
  }
  // Create a new profile.
  if (FAILED(hRes = lpProfAdmin->CreateProfile(szProfile,   // Name of new profile.
                         NULL,     // Password for profile.
                         NULL,     // Handle to parent window.
                         NULL)))    // Flags.
  {
    cout<<"Error creating profile.";
    goto error;
  }

  // Get an IMsgServiceAdmin interface off of the IProfAdmin interface.
  if (FAILED(hRes = lpProfAdmin->AdminServices(szProfile,   // Profile that we want to modify.
                         NULL,     // Password for that profile.
                         NULL,     // Handle to parent window.
                         0,       // Flags.
                         &lpSvcAdmin))) // Pointer to new IMsgServiceAdmin.
  {
    cout<<"Error getting IMsgServiceAdmin interface.";
    goto error;
  }

  // Create the new message service for Exchange.
  if (FAILED(hRes = lpSvcAdmin->CreateMsgService("MSEMS",   // Name of service from MAPISVC.INF.
                          NULL,    // Display name of service.
                          NULL,    // Handle to parent window.
                          NULL)))   // Flags.
  {
    cout<<"Error creating Exchange message service.";
    goto error;
  }
    if (FAILED(hRes = lpSvcAdmin->GetMsgServiceTable(0,         // Flags.
                           &lpMsgSvcTable))) // Pointer to table.
  {
    cout<<"Error getting Message Service Table.";
    goto error;
  }

  // Set up restriction to query table.

  sres.rt = RES_CONTENT;
  sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;
  sres.res.resContent.ulPropTag = PR_SERVICE_NAME;
  sres.res.resContent.lpProp = &SvcProps;
  SvcProps.ulPropTag = PR_SERVICE_NAME;
  SvcProps.Value.lpszA = "MSEMS";
  // Query the table to obtain the entry for the newly created message service.

  if (FAILED(hRes = HrQueryAllRows(lpMsgSvcTable,
                   (LPSPropTagArray)&sptCols,
                   &sres,
                   NULL,
                   0,
                   &lpSvcRows)))
  {
    cout<<"Error querying table for new message service.";
    goto error;
  }
  // Set up a SPropValue array for the properties that you have to configure.
  // First, the server name.
  ZeroMemory(&rgval[1], sizeof(SPropValue) );
  rgval[1].ulPropTag = PR_PROFILE_UNRESOLVED_SERVER;
  rgval[1].Value.lpszA = szServer;

  // Next, the mailbox name.
  ZeroMemory(&rgval[0], sizeof(SPropValue) );
  rgval[0].ulPropTag = PR_PROFILE_UNRESOLVED_NAME;

  rgval[0].Value.lpszA = szMailbox;

  // Configure the message service by using the previous properties.

    if (FAILED(hRes = lpSvcAdmin->ConfigureMsgService(
    (LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb, // Entry ID of service to configure.
    NULL,                            // Handle to parent window.
    0,                             // Flags.
    2,                             // Number of properties we are setting.
    rgval)))                          // Pointer to SPropValue array.
  {
    cout<<"Error configuring message service.";
    goto error;
  }
 
LPMAPISESSION       m_mapiSession;
  LPSTR lpszProfile;
lpszProfile= "temp";
if (FAILED(hRes = MAPILogonEx(0,lpszProfile,  NULL,    MAPI_EXTENDED | MAPI_NEW_SESSION | MAPI_UNICODE | MAPI_LOGON_UI, &m_mapiSession)))
{
    cout<<"Error new";
    goto error;
  }
  goto cleanup;
error:
  cout<<" hRes = 0x"<<hex<<hRes<<dec<<endl;
  cin >>a ;
  return FALSE;
cleanup:
  // Clean up.
  if (lpSvcRows) FreeProws(lpSvcRows);
  if (lpMsgSvcTable) lpMsgSvcTable->Release();
  if (lpSvcAdmin) lpSvcAdmin->Release();
  if (lpProfAdmin) lpProfAdmin->Release();

  MAPIUninitialize();
  cout <<"done";
  cin>>a;
  return TRUE;
}


parul


Viewing all articles
Browse latest Browse all 7132

Trending Articles