# Send an error message from a c function by using WSTP library

Consider that Func is a function written in c language by using WSTP library. In some situations, it can return an error to Mathematica.

void Func()
{
...
WSPutSymbol(stdlink, "$Failed"); }  In addition to show a$Failed message, I want to show an error message (a red colored message). How can I do this?

• Section 1.6 in the tutorial I suggested to you. – Szabolcs Aug 31 '18 at 13:58
• Here is an example of sending a message from a library: stackoverflow.com/a/6527191/4712538 – Jason B. Aug 31 '18 at 13:58

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;