Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2007

Tip: Looking for answers? Try searching our database.

Need help with C Header file definition to C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason - 23 Jun 2007 02:21 GMT
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 ;
Jason - 26 Jun 2007 17:30 GMT
Come on guys there has to be some brave soul out there who knows how
to do this.  Any help would be extremely appreciated.
Mattias Sjögren - 30 Jun 2007 23:11 GMT
>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

Signature

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


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.