Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am trying to use various unmanaged code in manged code, one of the situation which concerns me is this :

in my c/c++ class i have a structure, this structure contains many nested structure, many int's, char's, char *, char** as its variables in its declaration. which are all initialized after running my c/c++ code.

eg of my structure in c/c++ :

CSS
struct my_company {
    int total_emp;
    char *country;

    //my nested structure 1 pointer to pointer (**)
    struct account_branch **ac_branch;

    /* my nested structure 2 pointer to structure variable */
    struct sales_branch *s_branch;

    /* my  pointer to char variable */
    char *location;

    /* my nested structure 3 a structure variable */
    equipment eqp;    
};


CSS
struct account_branch {
    unsigned int type;

    /* my acount strucuture contains a pointer to int variable */
    int *accountants;
    char *acc_location;
};


my other nested structure of my_company can be seen as my struct account_branch.

now i run my c/c++ code function and declare my struct as :

struct my_company *local_company;

after some processing i fill up all the values of it now i have my structure variable local_company which contains address of memory location where it has been holding values of various of its variables, i want to pass this location to my c# (wrapper class method),

my questions are :

1.)Is it possible to pass such a reference without losing any data
2.)how would i do it if so
3.)please explain me as i am new to c++/clr.

Thanks.
Posted
Comments
Philippe Mori 15-May-15 12:46pm    
I think that for scenario, I would use mixed mode code and do the conversion by hand and make the C# code more user friendly.
KarstenK 15-May-15 13:31pm    
I would strongly advise against it. Make a complete data struct with native types and transfer it as a pointer. This works and you can go on and code program instead of memory problems.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900