-1

i'm new to c++ i tried to search the web for help, but has no sucess, I'm Trying to pass arguments to the CreateProfileWithIProfAdmin Function, i guess that the reason i fail to pass the args it's because it's a bool type function which accept only boolean values, however, i tried already to add (int argc, char *argv[]) to main() and to the CreateProfileWithIProfAdmin Function,

as you can see down inside the function there's variables for szProfile, szMailbox etc. my goal is to pass those variable directly from the commandline with args1 args2 etc.

What i need to do to pass char args to the function?

I'm VERY new to c++ and really appreciate any help, thanks...

// Function declarations
bool CreateProfileWithIProfAdmin();


void main()
{

    CreateProfileWithIProfAdmin();
}


// The Function i want to pass args to.. specifically the 3 chars variables
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[10];               // 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 };
Avshalom
  • 8,657
  • 1
  • 25
  • 43
  • 4
    `main` must have the return type `int`, not `void`. Next, your `CreateProfileWithIProfAdmin` does not accept any arguments, `bool` or otherwise (it has a `bool` return type though). Apart from that it’s not very clear what exactly you want to achieve because your explanation contradicts itself. – Konrad Rudolph Jan 26 '16 at 17:49
  • *"i fail to pass the args it's because it's a bool type function which accept only boolean values"* - it returns `bool`, that's all. Look up functions in C++. – LogicStuff Jan 26 '16 at 17:50
  • in c++ do i must to declare a type for a function? and if yes, does the bool is really needed in this case? – Avshalom Jan 26 '16 at 17:56
  • 1
    `bool func()` means `func` returns a `bool` to the caller. `void func(bool name)` means `func` is called with a `bool` and refers to that bool as `name`. `bool func(bool name)` means `func` takes in a `bool` and returns a `bool` to the caller. – user4581301 Jan 26 '16 at 18:00
  • I would suggest that if you're as new to c++ as your understanding of function return types and parameters suggests, the program you are trying to write here is a bit beyond your current capacity. You should devote some time towards learning at least a basic understanding of the language before taking on such a challenge. – mah Jan 26 '16 at 18:00
  • 2
    http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – eerorika Jan 26 '16 at 18:01
  • 1
    Also a decent read: [A Tour of C++. Part one: The Basics.](https://isocpp.org/images/uploads/2-Tour-Basics.pdf) – user4581301 Jan 26 '16 at 18:10

1 Answers1

1

I strongly suggest you grab a book on C++.

bool callingThisFunction(const char * ptr1, const char * ptr2, const char * ptr3)
{
    return true;
}

int main(int argc, char ** argv)
{
    if (argc == 4)
    {
        char * executeablename = argv[0];
        char * p1 = argv[1];
        char * p2 = argv[2];
        char * p3 = argv[3];
        bool result = callingThisFunction(p1, p2, p3);
    }
    return 0;
}

There is a bit of madness in doing what I wrote up there. It certainly is unsafe.

Johannes
  • 6,490
  • 10
  • 59
  • 108
  • About the best you're going to be able to do with an answer to this question without writing a textbook chapter. Recommend adding two things: explaining what you are doing with `const` and why it's important, and use at least one of the parameters in the function as an example. – user4581301 Jan 26 '16 at 18:08