Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Conversion Error

Posted on 2006-06-15
12
Medium Priority
?
1,635 Views
Last Modified: 2012-06-27
I currently have a simple C++ win32 console application in visual studio 2005. I am trying to do some stuff with MAPI and I get this error when I run the code below. I marked the line where the error is occuring. Anyone gotta fix?

error C2664: 'IProfAdmin::CreateProfile' : cannot convert parameter 1 from 'char [80]' to 'LPTSTR'

-------------------------- Begin Code --------------------------

#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <mapix.h>
#include <MAPITAGS.H>
#include <MAPIUTIL.H>
#include "edkmdb.h"

using namespace std;

bool CreateProfileWithIProfAdmin();

int main() {
    CreateProfileWithIProfAdmin();

    return 0;
}

bool CreateProfileWithIProfAdmin()
{
    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[80] = {0}; // String for profile name.
    char szMailbox[80] = {0}; // String for mailbox name.
    char szServer[80] = {0}; // String for server name.

    // This indicates columns we want returned from HrQueryAllRows.
    enum {iSvcName, iSvcUID, cptaSvc};
    SizedSPropTagArray(cptaSvc,sptCols) = { cptaSvc, PR_SERVICE_NAME, PR_SERVICE_UID };

    // Get configuration info from user.
    cout<<"Enter name for profile: ";
    cin>>szProfile;
    cout<<"Enter Exchange mailbox name: ";
    cin>>szMailbox;
    cout<<"Enter Exchange server name: ";
    cin>>szServer;

    // Initialize MAPI.

    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.      <<<<<<<<< ERROR occurs here <<<<<<<<<<<
        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;
    }

    // We now need to get the entry id for the new service.
    // This can be done by getting the message service table
    // and getting the entry that corresponds to the new service.

    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 get 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;
    }

    // Setup a SPropValue array for the properties you need 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 with the above 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;
    }

    goto cleanup;

error:
    cout<<" hRes = 0x"<<hex<<hRes<<dec<<endl;
    return FALSE;

cleanup:
    // Clean up.
    if (lpSvcRows) FreeProws(lpSvcRows);
    if (lpMsgSvcTable) lpMsgSvcTable->Release();
    if (lpSvcAdmin) lpSvcAdmin->Release();
    if (lpProfAdmin) lpProfAdmin->Release();

    MAPIUninitialize();
    return TRUE;

}

-------------------------- End Code --------------------------




0
Comment
Question by:inviser
  • 5
  • 4
  • 3
12 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16917151
You're probably UNICODE somewhere, try

#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <mapix.h>
#include <MAPITAGS.H>
#include <MAPIUTIL.H>
#include "edkmdb.h"
#include <tchar.h>

using namespace std;

bool CreateProfileWithIProfAdmin();

int main() {
    CreateProfileWithIProfAdmin();

    return 0;
}

bool CreateProfileWithIProfAdmin()
{
    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.
    TCHAR szProfile[80] = {0}; // String for profile name.
    TCHAR szMailbox[80] = {0}; // String for mailbox name.
    TCHAR szServer[80] = {0}; // String for server name.

    // This indicates columns we want returned from HrQueryAllRows.
    enum {iSvcName, iSvcUID, cptaSvc};
    SizedSPropTagArray(cptaSvc,sptCols) = { cptaSvc, PR_SERVICE_NAME, PR_SERVICE_UID };

    // Get configuration info from user.
    cout<<"Enter name for profile: ";
    cin>>szProfile;
    cout<<"Enter Exchange mailbox name: ";
    cin>>szMailbox;
    cout<<"Enter Exchange server name: ";
    cin>>szServer;

    // Initialize MAPI.

    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.      <<<<<<<<< ERROR occurs here <<<<<<<<<<<
        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;
    }

    // We now need to get the entry id for the new service.
    // This can be done by getting the message service table
    // and getting the entry that corresponds to the new service.

    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 get 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;
    }

    // Setup a SPropValue array for the properties you need 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 with the above 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;
    }

    goto cleanup;

error:
    cout<<" hRes = 0x"<<hex<<hRes<<dec<<endl;
    return FALSE;

cleanup:
    // Clean up.
    if (lpSvcRows) FreeProws(lpSvcRows);
    if (lpMsgSvcTable) lpMsgSvcTable->Release();
    if (lpSvcAdmin) lpSvcAdmin->Release();
    if (lpProfAdmin) lpProfAdmin->Release();

    MAPIUninitialize();
    return TRUE;

}

'TCHAR' instead of 'char' might help here.
0
 
LVL 6

Author Comment

by:inviser
ID: 16922016
Thanks for the help so far, I did as you said and it got rid of the errors, but now I get these errors. Any ideas?

Error      1      error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'TCHAR [80]' (or there is no acceptable conversion)      c:\documents and settings\blewis.smmnet\my documents\visual studio 2005\projects\mapi\mapi\main.cpp      40      
Error      2      error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'TCHAR [80]' (or there is no acceptable conversion)      c:\documents and settings\blewis.smmnet\my documents\visual studio 2005\projects\mapi\mapi\main.cpp      42      
Error      3      error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'TCHAR [80]' (or there is no acceptable conversion)      c:\documents and settings\blewis.smmnet\my documents\visual studio 2005\projects\mapi\mapi\main.cpp      44      
Error      4      error C2664: 'IMsgServiceAdmin::CreateMsgService' : cannot convert parameter 1 from 'const char [6]' to 'LPTSTR'      c:\documents and settings\blewis.smmnet\my documents\visual studio 2005\projects\mapi\mapi\main.cpp      91      
Error      5      error C2440: '=' : cannot convert from 'TCHAR [80]' to 'LPSTR'      c:\documents and settings\blewis.smmnet\my documents\visual studio 2005\projects\mapi\mapi\main.cpp      136      
Error      6      error C2440: '=' : cannot convert from 'TCHAR [80]' to 'LPSTR'      c:\documents and settings\blewis.smmnet\my documents\visual studio 2005\projects\mapi\mapi\main.cpp      141      
0
 
LVL 86

Expert Comment

by:jkr
ID: 16922372
Hm, that needed some fine tuning - try

#define UNICODE
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <mapix.h>
#include <MAPITAGS.H>
#include <MAPIUTIL.H>
#include "edkmdb.h"
#include <tchar.h>

#ifdef UNICODE
#define cout wcout
#define cin wcin
#endif

using namespace std;

bool CreateProfileWithIProfAdmin();

int main() {
    CreateProfileWithIProfAdmin();

    return 0;
}

bool CreateProfileWithIProfAdmin()
{
    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.
    TCHAR szProfile[80] = {0}; // String for profile name.
    TCHAR szMailbox[80] = {0}; // String for mailbox name.
    TCHAR szServer[80] = {0}; // String for server name.

    // This indicates columns we want returned from HrQueryAllRows.
    enum {iSvcName, iSvcUID, cptaSvc};
    SizedSPropTagArray(cptaSvc,sptCols) = { cptaSvc, PR_SERVICE_NAME, PR_SERVICE_UID };

    // Get configuration info from user.
    cout<<_T("Enter name for profile: ");
    cin>>szProfile;
    cout<<_T("Enter Exchange mailbox name: ");
    cin>>szMailbox;
    cout<<_T("Enter Exchange server name: ");
    cin>>szServer;

    // Initialize MAPI.

    if (FAILED(hRes = MAPIInitialize(NULL)))
    {
        cout<<_T("Error initializing MAPI.");
        goto error;
    }

    // Get an IProfAdmin interface.

    if (FAILED(hRes = MAPIAdminProfiles(0, // Flags.
        &lpProfAdmin))) // Pointer to new IProfAdmin.
    {
        cout<<_T("Error getting IProfAdmin interface.");
        goto error;
    }

    // Create a new profile.

    if (FAILED(hRes = lpProfAdmin->CreateProfile(szProfile, // Name of new profile.      <<<<<<<<< ERROR occurs here <<<<<<<<<<<
        NULL, // Password for profile.
        NULL, // Handle to parent window.
        NULL))) // Flags.
    {
        cout<<_T("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<<_T("Error getting IMsgServiceAdmin interface.");
        goto error;
    }

    // Create the new message service for Exchange.

    if (FAILED(hRes = lpSvcAdmin->CreateMsgService(TEXT("MSEMS"), // Name of service from MAPISVC.INF.
        NULL, // Display name of service.
        NULL, // Handle to parent window.
        NULL))) // Flags.
    {
        cout<<_T("Error creating Exchange message service.");
        goto error;
    }

    // We now need to get the entry id for the new service.
    // This can be done by getting the message service table
    // and getting the entry that corresponds to the new service.

    if (FAILED(hRes = lpSvcAdmin->GetMsgServiceTable(0, // Flags.
        &lpMsgSvcTable))) // Pointer to table.
    {
        cout<<_T("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 = _T("MSEMS");

    // Query the table to get 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;
    }

    // Setup a SPropValue array for the properties you need to configure.

    // First, the server name.
    ZeroMemory(&rgval[1], sizeof(SPropValue) );
    rgval[1].ulPropTag = PR_PROFILE_UNRESOLVED_SERVER;
    rgval[1].Value.lpszW = szServer;

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

    // Configure the message service with the above 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<<_T("Error configuring message service.");
        goto error;
    }

    goto cleanup;

error:
    cout<<_T(" hRes = 0x")<<hex<<hRes<<dec<<endl;
    return FALSE;

cleanup:
    // Clean up.
    if (lpSvcRows) FreeProws(lpSvcRows);
    if (lpMsgSvcTable) lpMsgSvcTable->Release();
    if (lpSvcAdmin) lpSvcAdmin->Release();
    if (lpProfAdmin) lpProfAdmin->Release();

    MAPIUninitialize();
    return TRUE;

}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Author Comment

by:inviser
ID: 16922439
Well, there are no more compiler errors now (thanks for that), but I do have some link errors now. You've done alot for me so far so I'll be sure to give you the points regardless, but if you have any ideas on what to do about links errors such as this I would appreciate it. I'm not sure exactly how to add MAPI33.DLL as a reference in my project, maybe that is why, but the dll is in the project directory.

Error      1      error LNK2019: unresolved external symbol _MAPIUninitialize@0 referenced in function "bool __cdecl CreateProfileWithIProfAdmin(void)" (?CreateProfileWithIProfAdmin@@YA_NXZ)      main.obj      
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 1400 total points
ID: 16922622
>>>> error C2679: binary '>>'

The error is because "cin >>" doesn't accept a UNICODE string as right operand. The last post of jkr won't help cause he turned the "cout >>" operations.

Go back to your last post. Include

   #include <string>

at the top.  

Add the function below above main:

istream& operator>> (istream& is, wchar_t wsz[])
{
    string line;
    getline(is, line);
    int i = 0;
    for (i = 0; i < line.length(); ++i)
    {
        wsz[i] = line[i];
    }
    wsz[i] = 0;
    return is;
}

Then, the error C2679 should be solved.

>>>> error C2664: 'IMsgServiceAdmin::CreateMsgService' : cannot convert parameter 1 from 'const char [6]' to 'LPTSTR'

turn the first argument to L"MSEMS".

>>>> error C2440: '=' : cannot convert from 'TCHAR [80]' to 'LPSTR'  

The function ZerMemory needs a char* as first argument (while you have a wchar_t*).  You could make a cast like that:

ZeroMemory((char*)/&rgval[1]), sizeof(SPropValue) );

and it should compile.

Regards, Alex





0
 
LVL 6

Author Comment

by:inviser
ID: 16922754
Alex, thanks for your help, I did as you said and it compiles fine. However, I have these link errors. Here is the code I am currently using now:

Error      2      error LNK2019: unresolved external symbol _MAPIUninitialize@0 referenced in function "bool __cdecl CreateProfileWithIProfAdmin(void)" (?CreateProfileWithIProfAdmin@@YA_NXZ)      main.obj      
Error      3      error LNK2019: unresolved external symbol _FreeProws@4 referenced in function "bool __cdecl CreateProfileWithIProfAdmin(void)" (?CreateProfileWithIProfAdmin@@YA_NXZ)      main.obj      
Error      4      error LNK2019: unresolved external symbol _HrQueryAllRows@24 referenced in function "bool __cdecl CreateProfileWithIProfAdmin(void)" (?CreateProfileWithIProfAdmin@@YA_NXZ)      main.obj      
Error      5      error LNK2019: unresolved external symbol _MAPIAdminProfiles@8 referenced in function "bool __cdecl CreateProfileWithIProfAdmin(void)" (?CreateProfileWithIProfAdmin@@YA_NXZ)      main.obj      
Error      6      error LNK2019: unresolved external symbol _MAPIInitialize@4 referenced in function "bool __cdecl CreateProfileWithIProfAdmin(void)" (?CreateProfileWithIProfAdmin@@YA_NXZ)      main.obj      
Error      7      fatal error LNK1120: 5 unresolved externals      C:\Documents and Settings\blewis.SMMNET\My Documents\Visual Studio 2005\Projects\MAPI\Debug\MAPI.exe      1      


---------------------- Begin Code ----------------------

#include <iostream>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <mapix.h>
#include <MAPITAGS.H>
#include <MAPIUTIL.H>
#include "edkmdb.h"
#include <tchar.h>

using namespace std;

bool CreateProfileWithIProfAdmin();

istream& operator>> (istream& is, wchar_t wsz[])
{
    string line;
    getline(is, line);
    int i = 0;
    for (i = 0; i < line.length(); ++i)
    {
        wsz[i] = line[i];
    }
    wsz[i] = 0;
    return is;
}

int main() {
    CreateProfileWithIProfAdmin();

    return 0;
}

bool CreateProfileWithIProfAdmin()
{
    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.
    TCHAR szProfile[80] = {0}; // String for profile name.
    TCHAR szMailbox[80] = {0}; // String for mailbox name.
    TCHAR szServer[80] = {0}; // String for server name.

    // This indicates columns we want returned from HrQueryAllRows.
    enum {iSvcName, iSvcUID, cptaSvc};
    SizedSPropTagArray(cptaSvc,sptCols) = { cptaSvc, PR_SERVICE_NAME, PR_SERVICE_UID };

    // Get configuration info from user.
    cout<<"Enter name for profile: ";
    cin>>szProfile;
    cout<<"Enter Exchange mailbox name: ";
    cin>>szMailbox;
    cout<<"Enter Exchange server name: ";
    cin>>szServer;

    // Initialize MAPI.

    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.      <<<<<<<<< ERROR occurs here <<<<<<<<<<<
        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(L"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;
    }

    // We now need to get the entry id for the new service.
    // This can be done by getting the message service table
    // and getting the entry that corresponds to the new service.

    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 get 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;
    }

    // Setup a SPropValue array for the properties you need to configure.

    // First, the server name.
    ZeroMemory((char*)&rgval[1], sizeof(SPropValue) );
    rgval[1].ulPropTag = PR_PROFILE_UNRESOLVED_SERVER;
    rgval[1].Value.lpszA = (char*)szServer;

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

    // Configure the message service with the above 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;
    }

    goto cleanup;

error:
    cout<<" hRes = 0x"<<hex<<hRes<<dec<<endl;
    return FALSE;

cleanup:
    // Clean up.
    if (lpSvcRows) FreeProws(lpSvcRows);
    if (lpMsgSvcTable) lpMsgSvcTable->Release();
    if (lpSvcAdmin) lpSvcAdmin->Release();
    if (lpProfAdmin) lpProfAdmin->Release();

    MAPIUninitialize();
    return TRUE;

}

---------------------- End Code ----------------------

0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 600 total points
ID: 16922871
Just add 'mapi32.lib', e.g. by using

#pragma comment(lib,"mapi32.lib")
0
 
LVL 86

Expert Comment

by:jkr
ID: 16922884
And if that still isn't enugh, add

#pragma comment(lib,"mapi.lib")

also.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 16923098
>>>>  Just add 'mapi32.lib'

The usual way is to add the libname in the

    Project Settings - Linker - Input - object/library modules (VC6)
    - separate with space from other libs -
or

   Project Properties - Configuration Properties - Linker - Input - Additional Dependencies (VC.NET)
   - add a new entry -


Regards, Alex
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 16923197
>>>> #pragma comment(lib,"mapi32.lib")

So, it will work, I recommend against that solution cause linker options belong to the project file. You wouldn't be able to convert the project to another IDE  or export a makefile if using the proprietary #pragme solution.

>>>> #ifdef UNICODE
>>>> #define cout wcout
>>>> #define cin wcin
>>>> #endif

I also recommend against that misuse of the preprocessor. It is definitively a hack.

Note, std::cout and std::cin were based on single-byte character strings while wcout/wcin handle UNICODE strings (UNICODE is a double-byte character set). If you want to have UNICODE strings only you simply could replace cout by wcout and cin by wcin. Note, you always have to use UNICODE strings then. Or, you do what I have posted: enhancing the istream class to accept UNICODE strings as operand by valid C++ means (I overloaded operator>>).

Regards, Alex



0
 
LVL 86

Expert Comment

by:jkr
ID: 16923248
#pragma (lib, "name.lib")

however works for all compilers and has the advantage that it can be used in conditional compilation statements. Furthermore it does not require to use an IDE, which techically has nothing to do with the compiler.
0
 
LVL 6

Author Comment

by:inviser
ID: 16923581
Thanks guys, I got it working
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question