[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

Need help with C Header file definition to C#

Jason

6/23/2007 1:21:00 AM

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 Answers

Jason

6/26/2007 4:31:00 PM

0

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)

6/30/2007 10:12:00 PM

0


>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.n... | http://www.dotneti...
Please reply only to the newsgroup.