This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
MathLink C Function


int MLMain(int argc, char **argv)
sets up communication between an external program started using Install and Mathematica.
  • The code for MLMain() is generated automatically by mprep or mcc.
  • MLMain() opens a MathLink connection using the parameters specified in argv, then goes into a loop waiting for CallPacket objects to arrive from Mathematica.
  • MLMain() is declared in the MathLink header file mathlink.h.
#include "mathlink.h"


/* a Microsoft Windows example WinMain routine */

int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow)
char buff[512];
char FAR * buff_start = buff;
char FAR * argv[32];
char FAR * FAR * argv_end = argv + 32;

     hinstPrevious = hinstPrevious; /* suppress warning */

if( !MLInitializeIcon( hinstCurrent, nCmdShow)) return 1;
MLScanString( argv, &argv_end, &lpszCmdLine, &buff_start);
return MLMain( (int)(argv_end - argv), argv);


int main(int argc, char* argv[])
return MLMain(argc, argv);