The tutorial I suggested to you has a complete example. See section 1.6. Please read through the entire first chapter.
Here's a copy of the code from there:
In your template file, ensure that both argument passing and return are set to Manual
, then add the following:
:Evaluate: AddTwo::ovflw = "The sum cannot fit into a C long type."
A modification of the addtwo
example:
void addtwo(void) {
long i, j, sum;
MLGetLongInteger(stdlink, &i);
MLGetLongInteger(stdlink, &j);
sum = i + j;
if(i>0 && j>0 && sum<0 || i<0 && j<0 && sum>0) {
MLEvaluate(stdlink, "Message[AddTwo::ovflw]");
MLNextPacket(stdlink);
MLNewPacket(stdlink);
MLPutSymbol(stdlink, "$Failed");
} else {
MLPutLongInteger(stdlink, sum);
}
}