Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 62 lines (52 sloc) 1.381 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT extern
#endif

DLLEXPORT double * ReturnADoubleArray()
{
    double *foo = malloc(3 * sizeof(double));
    foo[0] = 23.45;
    foo[1] = -99.87;
    foo[2] = 0.25;
    return foo;
}

DLLEXPORT double TakeADoubleArrayAndAddElements(double *arr)
{
    return arr[0] + arr[1];
}

DLLEXPORT char ** ReturnAStringArray()
{
    char **foo = malloc(2 * sizeof(char *));
    foo[0] = "La Trappe";
    foo[1] = "Leffe";
    return foo;
}

DLLEXPORT int TakeAStringArrayAndReturnTotalLength(char **arr)
{
    return (int)(strlen(arr[0]) + strlen(arr[1]));
}

typedef struct {
    long value;
} Struct;

DLLEXPORT Struct **ReturnAStructArray() {
    Struct **arr = (Struct **) malloc(3*sizeof(Struct *));
    arr[0] = malloc(sizeof(Struct));
    arr[1] = malloc(sizeof(Struct));
    arr[2] = malloc(sizeof(Struct));

    arr[0]->value = 2;
    arr[1]->value = 3;
    arr[2]->value = 5;

    return arr;
}

DLLEXPORT void TakeAStructArray(Struct **structs) {
    if(structs[0]->value != 7) printf("not ");
    printf("ok - struct in position 0, C-side\n");
    if(structs[1]->value != 11) printf("not ");
    printf("ok - struct in position 1, C-side\n");
    if(structs[2]->value != 13) printf("not ");
    printf("ok - struct in position 2, C-side\n");
}
Something went wrong with that request. Please try again.