none
Pass the C# structure to unmanaged code RRS feed

  • Question

  • Hi All,

    I have a doubt in passing the c# structure to unmanaged code.I need the equivalent of C in C#
    For example

    C structs

    typedef struct stacks 
    {
      NL_F1DNODE  * f1d;

    }NL_STACKS; 

    where NL_F1DNODE  

    typedef struct f1dnode {
    NL_FLAG *ptr;
    struct f1dnode *next;
    } NL_F1DNODE;

    And Function in C

    NL_VOID N_InitNurbs( NL_STACKS *S )

    I need the equivalent of the above mentioned both structure and function in c#.Please anyone guide me.Thanks in advance.


    MSS

    Tuesday, August 18, 2015 6:23 PM

Answers

  • Not sure what the problem is, just make some class that match those C structs:

    [StructLayout(LayoutKind.Sequential)]
    class NL_FLAG
    {
    ...
    }
    
    [StructLayout(LayoutKind.Sequential)]
    class NL_F1DNODE
    {
         NL_FLAG ptr;
         NL_F1DNODE next;
    }
    
    [StructLayout(LayoutKind.Sequential)]
    class NL_STACKS
    {
         NL_F1DNODE f1d;
    }
    
    [DllImport("SomeDllName")]
    static extern void N_InitNurbs(NL_STACKS S);
    

    Wednesday, August 19, 2015 6:36 AM
    Moderator

All replies

  • Not sure what the problem is, just make some class that match those C structs:

    [StructLayout(LayoutKind.Sequential)]
    class NL_FLAG
    {
    ...
    }
    
    [StructLayout(LayoutKind.Sequential)]
    class NL_F1DNODE
    {
         NL_FLAG ptr;
         NL_F1DNODE next;
    }
    
    [StructLayout(LayoutKind.Sequential)]
    class NL_STACKS
    {
         NL_F1DNODE f1d;
    }
    
    [DllImport("SomeDllName")]
    static extern void N_InitNurbs(NL_STACKS S);
    

    Wednesday, August 19, 2015 6:36 AM
    Moderator
  • Thank for your idea.I will try.

    MSS

    Wednesday, August 19, 2015 9:30 AM
  • Hi MSS,

    What's the problem now? Do you have any updates about Mike's solution?

    Currently I marked Mike's response as an answer, you can unmark if no help. Thanks.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Thursday, August 27, 2015 1:50 AM
    Tuesday, August 25, 2015 8:00 AM