Kjetil
March 19th, 2003, 03:46 AM
Hello,
I have some "old" c-code that I wrapp inside a Managed C++ code. This code include a union.
I have created a new equal "union" in the wrapper class with StructLayout(LayoutKind::Explicit). So fare so good!
Then I want to call a function in the c-code with a parameter of the union type. A method in the Managed C++ code have a parameter of the "new union".
/* old c-code union */
typedef union {
double val_double;
int val_int;
h_time val_time;
INT64 val_longlong;
char val_string[8];
} h_anytype;
/* new Managed C++ union */
[ StructLayout(LayoutKind::Explicit) ]
public __value struct H_anytype {
[FieldOffset(0)] double val_double;
[FieldOffset(0)] int val_int;
[FieldOffset(0)] h_time val_time;
[FieldOffset(0)] INT64 val_longlong;
[FieldOffset(0)] char val_string __nogc[8];
};
/* the Managed C++ method calling the the c function */
void ClassX::MethodX(H_anytype *pars)
{
/*
* Do the call to the old c-code function
* - functionX(h_anytype *pars);
*/
functionX(pars);
}
How do I cast the Managed C++ code "union" to the "old" c-code union?
I have some "old" c-code that I wrapp inside a Managed C++ code. This code include a union.
I have created a new equal "union" in the wrapper class with StructLayout(LayoutKind::Explicit). So fare so good!
Then I want to call a function in the c-code with a parameter of the union type. A method in the Managed C++ code have a parameter of the "new union".
/* old c-code union */
typedef union {
double val_double;
int val_int;
h_time val_time;
INT64 val_longlong;
char val_string[8];
} h_anytype;
/* new Managed C++ union */
[ StructLayout(LayoutKind::Explicit) ]
public __value struct H_anytype {
[FieldOffset(0)] double val_double;
[FieldOffset(0)] int val_int;
[FieldOffset(0)] h_time val_time;
[FieldOffset(0)] INT64 val_longlong;
[FieldOffset(0)] char val_string __nogc[8];
};
/* the Managed C++ method calling the the c function */
void ClassX::MethodX(H_anytype *pars)
{
/*
* Do the call to the old c-code function
* - functionX(h_anytype *pars);
*/
functionX(pars);
}
How do I cast the Managed C++ code "union" to the "old" c-code union?