Need help with C Header file definition to C# - DOTNET

This is a discussion on Need help with C Header file definition to C# - DOTNET ; Hi, I have a c dll which I need to link to from my C# code. I just want to warn you guys I am not very well versed in C or C++ so any help would be greatly appreciated. ...

+ Reply to Thread
Results 1 to 3 of 3

Need help with C Header file definition to C#

  1. Default Need help with C Header file definition to C#

    Hi,

    I have a c dll which I need to link to from my C# code. I just want
    to warn you guys I am not very well versed in C or C++ so any help
    would be greatly appreciated.

    I wanted to know if the structure I have shown should be modeled as a
    Struct or as a Class in C#. Also, since there are callbacks from the
    C side, how do I have to maintain my c# objects lifetime ? Finally,
    it is the question, of how this struct should look in C#. Again, any
    help would be greatly appreciated. Thanks in advance.


    #define INTERNAL_USE_ONLY /* For marking fields designated as
    internal use only */


    typedef struct _ARM_ROUND {
    double armr_unit ; /* unit of the rounding operation. eg: 0.125
    */
    char armr_target ;
    #define TARGET_INDEX 1
    #define TARGET_NETRATE 2
    #define TARGET_GROSSRATE 3
    char armr_method ;
    #define METHOD_CEIL 1
    #define METHOD_FLOOR 2
    #define METHOD_ROUND 3
    char *armr_next ; /* to next in link list */
    } ARM_ROUND ;

    typedef struct _ARMI_INFO {
    char *armi_next ; /* Ptr to next armp in linked list
    */
    int armi_stage_start_mo ;
    int armi_index ;
    char armi_index_subname[MAX_INDEXSUBNAME_CHARS+1]; /* LOOKBKnn or
    explicit subname */
    char armi_amort_type ;
    int armi_ntillreset ;
    int armi_resetper ;
    int armi_paym_ntillreset ;
    double armi_init_percap ;
    int armi_init_resetper ;
    char armi_negam_limit_action ;
    double *misc_uservals ;
    int *tranche_freqs
    double **vindexs
    char **class_vsubclasses ; /* the nodes directly under this
    class*/
    char pibond_issue_description [52] ;
    int optrt_nums[OPTR_MAX_TARGETS+1]
    INDEX **vindex_info ; /* vector of index info structures */
    ARM_ROUND *armi_roundp;
    char *grp_fullname ; /* descriptive name of the group */
    int ((CALLBACK_PREFIX *script_sym_fcn)(char *, char *, int,
    int)); /* optional user callback fcn */

    /* internal fields */
    INTERNAL_USE_ONLY double armi_subpool_frac ;
    INTERNAL_USE_ONLY double armi_subpool_netrate ;
    INTERNAL_USE_ONLY double armi_subpool_servrate ;
    } ARM_INFO ;


  2. Default Re: Need help with C Header file definition to C#

    Come on guys there has to be some brave soul out there who knows how
    to do this. Any help would be extremely appreciated.


  3. Default Re: Need help with C Header file definition to C#


    >Also, since there are callbacks from the
    >C side, how do I have to maintain my c# objects lifetime ?


    The lifetime of what object?


    >I wanted to know if the structure I have shown should be modeled as a
    >Struct or as a Class in C#. [...] Finally,
    >it is the question, of how this struct should look in C#.


    In this case I don't think it matters, but I generally prefer structs
    over classes. Try this definition

    struct ARM_INFO {
    public IntPtr armi_next;
    public int armi_stage_start_mo;
    public int armi_index;
    [MarshalAs(UnmanagedType.ByValTStr,
    SizeConst=MAX_INDEXSUBNAME_CHARS+1)]
    public string armi_index_subname;
    public byte armi_amort_type;
    public int armi_ntillreset;
    public int armi_resetper;
    public int armi_paym_ntillreset;
    public double armi_init_percap;
    public int armi_init_resetper;
    public byte armi_negam_limit_action;
    public IntPtr misc_uservals;
    public IntPtr tranche_freqs;
    public IntPtr vindexs;
    public IntPtr class_vsubclasses;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=52)]
    public string pibond_issue_description;
    [MarshalAs(UnmanagedType.ByValArray,
    SizeConst=OPTR_MAX_TARGETS+1)]
    public int[] optrt_nums;
    public IntPtr vindex_info;
    public IntPtr armi_roundp;
    public string grp_fullname;
    public YourCallbackDelegateType script_sym_fcn;
    /* internal fields */
    private double armi_subpool_frac;
    private double armi_subpool_netrate;
    private double armi_subpool_servrate;
    }



    Mattias

    --
    Mattias Sjögren [C# MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

+ Reply to Thread

Similar Threads

  1. Module definition file
    By Application Development in forum c++
    Replies: 1
    Last Post: 11-21-2007, 03:08 AM
  2. Definition in Header files
    By Application Development in forum C
    Replies: 31
    Last Post: 10-25-2007, 04:40 PM
  3. Definition in Header files
    By Application Development in forum c++
    Replies: 5
    Last Post: 10-24-2007, 03:53 AM
  4. Where is the definition of File.read()?
    By Application Development in forum RUBY
    Replies: 9
    Last Post: 09-07-2007, 02:52 AM
  5. multiple definition error - global variable header file
    By Application Development in forum c++
    Replies: 7
    Last Post: 06-28-2007, 03:45 AM