Message Boards Message Boards

0
|
3652 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Building Console Application Linking Mathematica

Posted 11 years ago
I am very new to Mathematica and I am trying to create a console application using Visual Studio C++. I have followed a example code to see whether it works or not. The codes are as follows.
 #include <mathlink.h>
 
 #include <stdio.h>
 
 int main(int argc, char *argv[]) {
     MLENV env;
     MLINK link;
     int errno;
     int packet;

    env = MLInitialize(0);

    /* consider using MLOpenString instead here: */
    link = MLOpenArgcArgv(env, argc, argv, &errno);

    MLActivate(link);

    /* send 42+137 using the full form Plus[42, 137] */
    MLPutFunction(link, "Plus", 2);
    MLPutInteger(link, 42);
    MLPutInteger(link, 137);
    MLEndPacket(link);

    /* get packets until we find a ReturnPacket or error */
    while ((packet = MLNextPacket(link)) && packet != RETURNPKT)
        MLNewPacket(link);

    if (MLError(link))
        printf("error.\n");
    else {
            int result;
        MLGetInteger(link, &result); /* we know that the result is an integer in this case */
        printf("result: %d\n", result);
    }

    getchar();
    return 0;
}

When I run this code, it runs and gives me the dialogue boxes below. However, I am not sure what to key in there.

What link am I to create or link to? What am I doing wrong?

Thanks

POSTED BY: Arvind Rajan
2 Replies
I think it's looking for MathKernel.exe
POSTED BY: Frank Kampas
yes, i solved it! thanks
POSTED BY: Arvind Rajan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract