/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <stdarg.h>

typedef void (__stdcall *callback)(char *);

static callback cb;

/* start hacks */
#define printf my_printf

int my_printf(char *fmt,...)
{
    int n;
    char buf[1000];
    va_list argptr;
    va_start(argptr, fmt);
    n = vsprintf(buf, fmt, argptr);
    va_end(argptr);
    cb(buf);
    return n;
}
/* end hacks */

#ifdef __cplusplus
extern "C"
{
    __declspec(dllexport) void __stdcall set_callback(callback newcb);
    __declspec(dllexport) void __stdcall dosomething();
}
#endif

__declspec(dllexport) void __stdcall set_callback(callback newcb)
{
    cb = newcb;
}

__declspec(dllexport) void __stdcall dosomething()
{
    printf("bla bla\n");
    printf("%d\n", 123);
    printf("%s\n", "ABC");
}
