problem passigng variables from c# to mined C++

hey guys,

im having quite a small problem yet i dont know the solution to.

i have a c# application, and a managed c++ dll. in the c++ dll i have a native implementation of a funtion, and in the managed c++ i wrap that native implementation with another class.
and i pass form c# to managed c++ class 2 objects with abunch of variables in each.

that managed c++ class intrun passes these values to the native class, calculates something, assigns the result back in variables. and as soon i get mack to my managed c++ class, from the native class, these values disaplear, and im back with my old values.
that will result in old values in c#.

here is my code:

managed mix c++


    public __nogc class tkRigidBody
    {

        ...

        void GetTransformationsSeperate(float p11, float p12, float p13,
                                float m11, float m12, float m13,
                                float m21, float m22, float m23,
                                float m31, float m32, float m33)
        {
            m_Transformations = m_RigidBody->GetTransform();
           
            p11 = m_Transformations.pos[0]; p12 =  m_Transformations.pos[1]; p13 =  m_Transformations.pos[2];

            m_Position[0] = m_Transformations.pos[0];
            m_Position[1] = m_Transformations.pos[1];
            m_Position[2] = m_Transformations.pos[2];

            m11 = m_Transformations.rot[0][0]; m12 = m_Transformations.rot[0][1]; m13 = m_Transformations.rot[0][2];
            m21 = m_Transformations.rot[1][0]; m22 = m_Transformations.rot[1][1]; m23 = m_Transformations.rot[1][2];
            m31 = m_Transformations.rot[2][0]; m32 = m_Transformations.rot[2][1]; m33 = m_Transformations.rot[2][2];
        }
    };

/**************************************************
                  MANAGED FOR TOKAMAK PHYSICS
**************************************************/

    public __gc class tkMRigidBody
    {

        ...

        void GetTransformations(ngVector3 *position, ngMatrix *rotation)
        {
            t->GetTransformationsSeperate(position->X, position->Y, position->Z,
                rotation->M11, rotation->M12, rotation->M13,
                rotation->M21, rotation->M22, rotation->M23,
                rotation->M31, rotation->M32, rotation->M33);
        }
    };

 


and here is my c# code that i call the "GetTransformations" function from the "tkMRigidBody" managed class.



m_RigidBody.GetTransformations(m_vPosition, m_mRotation);

 


so why r my variables loosing there values what am i doing wrong


Answer this question

problem passigng variables from c# to mined C++

  • Hakop000

    If you want to change the arguments of GetTransformationsSeperate, you have to use pointer or reference notation.


    void GetTransformationsSeperate(float &p11, float &p12, float &p13,
                                    float &m11, float &m12, float &m13,
                                    float &m21, float &m22, float &m23,
                                    float &m31, float &m32, float &m33)

     
         

  • BruceH12

    thats wat i tried, but it told me, "error C2664: 'tkRigidBody::GetTransformationsSeperate' : cannot convert parameter 1 from 'float' to 'float &'"
    and notice that im using "position->X" to pass to the function.


  • Seth M. Livingston

    Only lvalues can be bound to non-const references. I guess ngVector3::X etc. are properties where the getter returns an rvalue. You could use autos to hold the values an assign back to the properties (which would call the setter). E.g.:



    void GetTransformations(ngVector3 *position, ngMatrix *rotation)
    {
       float posX, posY, posZ, rotM11 ... ; // all LValues
       t->GetTransformationsSeperate(posX, posY, posZ,  rotM11, ..);
       position->X = posX; // invokes setter
       // ...
    }

     


    -hg


  • problem passigng variables from c# to mined C++