0

I need to use a native dll in my c# program which is written in c/c++. One of the functions of this dll that i need to use in my program, gets a struct as its parameter.

typedef struct
{
    REPLY_TYPE      replyType;

    union
    {
        POSITIVE_REPLY  positiveReply;
        NEGATIVE_REPLY  negativeReply;
    }
    message;

}
REPLY, *LPREPLY;

and the POSITIVE_REPLY and NEGATIVE_REPLY fiels are another structs :

typedef struct
{
    BYTE    bCommandCode;
    BYTE    bParameterCode;

    struct
    {
        BYTE    bE1;
        BYTE    bE0;
    }
    ErrorCode;

    struct
    {
        DWORD   dwSize;
        BYTE    bBody[ MAX_DATA_ARRAY_SIZE];
    }
    Data;
}
NEGATIVE_REPLY, *LPNEGATIVE_REPLY;

How should I do this ? thanks.

  • look at this http://stackoverflow.com/questions/569603/using-c-class-dll-in-c-sharp-application – Jayram Jun 22 '13 at 04:33
  • sorry but I think my problem is different from that, I just need to know how should I marshal this type of code in c#. – Hamid Adldoost Jun 22 '13 at 04:39
  • 1
    You declare unions in C# by using the [StructLayout(LayoutKind.Explicit)] attribute on the structure declaration. Simply google "c# declare union" to find *many* relevant hits. – Hans Passant Jun 22 '13 at 13:18
  • 1
    possible duplicate of [C++ union in C#](http://stackoverflow.com/questions/126781/c-union-in-c-sharp) – Hans Passant Jun 22 '13 at 13:20

0 Answers0