Using a structure defined (unmanaged code) in a managed code.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sgunnala
    New Member
    • Jan 2007
    • 1

    #1

    Using a structure defined (unmanaged code) in a managed code.

    Hello,

    i want to use the unmanaged code in CSharp.

    the structure defined in the cpp dll is

    typedef struct XTRAP_CLIENT_LI ST
    {
    char prnNetAdd[100];
    char hostAddress[100];
    XTYPE_ADDESS ClientType;
    struct XTRAP_CLIENT_LI ST* next;
    } XTRAP_CLIENT_LI ST;

    typedef XTRAP_CLIENT_LI ST FAR * LPXTRAP_CLIENT_ LIST;

    how to define this structure in c# .net. and how to use the function which is using the structure.

    i have defined the structure as

    public struct XTRAP_CLIENT_LI ST
    {
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 100)]
    public string prnNetAdd;

    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 100)]
    public string hostAddress;
    public XTYPE_ADDESS ClientType;
    public IntPtr next;

    }

    But i don't know how to use use the IntPtr in my function.
  • radcaesar
    Recognized Expert Contributor
    • Sep 2006
    • 759

    #2
    Try like this,

    IntPtr handle = this.ServiceHan dle;

    myServiceStatus .currentState = (int)State.SERV ICE_START_PENDI NG; //0x00000002
    myServiceStatus .checkPoint = 1;
    myServiceStatus .waitHint = 5000;
    SetServiceStatu s(handle, ref myServiceStatus );


    Originally posted by sgunnala
    Hello,

    i want to use the unmanaged code in CSharp.

    the structure defined in the cpp dll is

    typedef struct XTRAP_CLIENT_LI ST
    {
    char prnNetAdd[100];
    char hostAddress[100];
    XTYPE_ADDESS ClientType;
    struct XTRAP_CLIENT_LI ST* next;
    } XTRAP_CLIENT_LI ST;

    typedef XTRAP_CLIENT_LI ST FAR * LPXTRAP_CLIENT_ LIST;

    how to define this structure in c# .net. and how to use the function which is using the structure.

    i have defined the structure as

    public struct XTRAP_CLIENT_LI ST
    {
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 100)]
    public string prnNetAdd;

    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 100)]
    public string hostAddress;
    public XTYPE_ADDESS ClientType;
    public IntPtr next;

    }

    But i don't know how to use use the IntPtr in my function.

    Comment

    Working...