How to marshal a linked list from C++ to C# RRS feed

  • Question

  • I have a native C function that returns a linked list in the following form:
    It actually returns a vlist_s *.

    The vlist is single linked list that stores void pointers.
    It has a cursor to traverse the list.
    typedef struct vlist_node_s{
    void * item;
    struct vlist_node_s * next;
    } vlist_node_t;

    typedef struct vlist_s{
    struct vlist_node_s * head;
    struct vlist_node_s * tail;
    struct vlist_node_s * cursor;
    struct vlist_node_s * cursor_backlink;
    unsigned int cursor_index;
    unsigned int count;
    void *(VLIST_CDECL *malloc) (size_t);
    void (VLIST_CDECL *free) (void*);
    } vlist_t;

    Is there any way to pass the returned vlist_s pointer back to the C# method that made the original call?

    Wednesday, August 16, 2006 3:33 PM

All replies

  • If you have an idea what is void* item, you can do this using IntPtr and different Marshal class functions. However, I suggest you to write C++/CLI wrapper and convert this list to ArrayList or List<> in C++ code. Writing such things in C# can be nightmare.
    Wednesday, August 16, 2006 4:53 PM