none
Interop C to C# RRS feed

  • Question

  • Hello. Could you specify links to clear rules on how the laws of the unmanaged types is displayed in the language with the c # types.  I'm trying to write a managed wrapper for c # library and very foul. Here is a simplified example, for which I can't write wrapper:
    Sorry for the terrible knowledge of English, Russian Forum answers No.
    #define LONGLONG long long
    
    typedef struct
    {
       //...
       char* filename;
       //...
       char zcmptype[12];
    }TColumn;
    
    
    typedef struct
    {
       //...
       LONGLONG* headstart;
       //...
       TColumn* tableptr;
    
    }FitsFile;
    How to implement this definition in c #?
    Friday, October 23, 2009 6:13 PM

Answers

  • [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
    public struct TColumn {
        [MarshalAs(UnmanagedType.LPStr)]
        public string filename;
        
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst=12)]
        public string zcmptype;
    }
    [StructLayout(LayoutKind.Sequential)]
    public struct FitsFile {
        public System.IntPtr headstart;
        public System.IntPtr tableptr;
    }
    • Marked as answer by OlegGel Saturday, October 24, 2009 11:14 AM
    Saturday, October 24, 2009 11:14 AM