Our version of this now-famous program is a system function that returns a scalar containing the text “Hello World!”:

#include <stdio.h>
#include "idl_export.h"
IDL_VPTR hello_world(int argc, IDL_VPTR argv[])
{
return(IDL_StrToSTRING("Hello World!"));
}

This is about as simple as an IDL system routine can be. The function IDL_StrToSTRING(), returns a temporary variable which contains a scalar string. Since this is exactly what is wanted, hello_world() returns the variable.

After compiling this function into a sharable object (named, for example, hello_exe), we can link it into IDL with the following LINKIMAGE call:

LINKIMAGE, 'HELLO_WORLD', 'hello_exe', 1, 'hello_world', $ 
MAX_ARGS=0, MIN_ARGS=0

Now we can issue the IDL command:

PRINT, HELLO_WORLD()

IDL displays:

Hello World!