I want to use C++ class in C#.
In C++ my .h file is like this:
struct XMFloat3
{
public:
float x; float y; float z;
XMFloat3(){}
XMFloat3(float _x, float _y,float _z)
{
x = _x;
y = _y; z = _z;
}
};
class Car
{
public:
XMFloat3 m_position;
char* m_name;
int m_model;
double m_price;
void setPosition(XMFloat3);
void setName(char* );
void setModel(int);
void setPrice(double);
XMFloat3 getPosition() { return m_position; }
char* getName() { return m_name; }
int getModel() { return m_model; }
double getPrice() { return m_price; }
void SetInformation(XMFloat3 position,char* name, int model,double price);
~Car(void);
static Car* getInstance();
private:
Car(void){ }
Car(XMFloat3 position,char* name,int model,double price){ }
static Car* instance;
};
I create clr\library project with Wrapper Class definition like:
public ref class WrapperClass
{
public:
WrapperClass();
void setInformation(XMFloat3 position,String^ name,int model,double price);
void setPosition(XMFloat3);
void setPosition(float x,float y,float z);
XMFloat3 getPosition() { return obj->getPosition(); }
void setName(String^ name);
String^ getName() { return gcnew String(obj->getName()); }
void setModel(int);
int getModel() { return obj->getModel(); }
void setPrice(double);
double getPrice() { return obj->getPrice(); }
float getX() { return obj->getX(); }
~WrapperClass();
private:
Car *obj;
};
.....................................................................................
But when i use this Wrapper class function getPosition() in C#, in C# getPosition() Declaration is like:
XMFloat3* getPosition(XMFloat *);
That's not perfect for my use please tell me if i doing any wrong up there or suggest how to use User Defined Datatype in such scenario.
And 2nd question is How User Defined data types are access or use in C#. e.g if i want to pass XMFloat3 data from C# how is it possible?? (I create XMFloat3 struct in C# .cs file and try to use it but its give type matching error.
In C# setPosition declaration for Wrapper Class is like: public void setPosition(XMFloat3 t); Error is Type Mismatch CSharp.XMFloat3 to WrapperDll.XMFloat3.
Please tell me how to use above Class in C#.
Thanks