I usually do it like this

mystruct.h: 
    
    
    typedef struct MyStruct {
      int width, length, mipmaps, pixels;
    } MyStruct;
    
    

mystruct.c: 
    
    
    #include <stdio.h>
    #include "mystruct.h"
    
    void printMyStruct(MyStruct ms) {
      printf("from c\t: test.width %d\n, ms.width);
      printf("from c\t: test.length %d\n, ms.length);
    }
    

caller.nim: 
    
    
    {.passC: "-I.".}
    type
      MyStruct {.header: "\"mystruct.h\"", importc: "MyStruct".} = object
        width, length, mipmaps, pixels: cint
    
    
    proc printMyStruct(ms: MyStruct)
      {.importc: "printMyStruct", dynlib:"./mystruct.dll".}
    
    var ms = MyStruct(width: 5.cint, length: 7.cint)
    
    echo "from nim: test.width ", ms.width
    echo "from nim: test.length ", ms.length
    
    printMyStruct(ms)
    

compile: 
    
    
    gcc -shared -o mystruct.dll -fPIC mystruct.c
    nim c -r caller
    

Reply via email to