Wrapper for C++ to be used in C# (as dll)

Hello,
I want to use this function in my C# project:

typedef float3 vec;
class OBB {
public:
vec pos;vec r; vec axis[3];
static OBB OptimalEnclosingOBB(const vec *pointArray, int numPoints);
}

So I need to write a wrapper that will go something like this:

using namespace System;
using namespace msclr::interop;

#if defined(__cplusplus)
extern "C" {
#endif
__declspec(dllexport) ??? OEOBB_Wrapper(???, int numPoints);

#if defined(__cplusplus)
}
#endif

String^ OEOBB_Wrapper(float[][], int i) {
// some code casting float[][] to vec *pointArray
// RerturnValue OptimalEnclosingOBB(const vec *pointArray, int numPoints);
// casting ReturnValue into something C# can read
return ??;
}
But I have 2 problems,
The input: vec *pointArray type is not defined in C# so which type I can use instead and how do I cast it?
The output: OBB class is not defined in C#, so what kind of return value my wrapper can use instead (after getting the OBB from the function)?
Why don't you create a C++/CLI assembly and wrap your code into a managed class. Then you should be able to use this managed class in C#.
I've been told that I can write a wrapper in the C++ code itself but I don't know how to work with MarshalAs etc for the types that not supported in C#.

What Im asking basically is how do I cast/transform float[][] to/from const vec *pointArray as the input and how do I cast/transform the class OBB as the output back to C#?
How is this float3 defined?
basically 3 floats. here is the full definition:
class float3
{
public:
enum
{
Size = 3
};
float x;
float y;
float z;
float3() {}
/// Constructs a new float3 with the value (x, y, z).
/** @see x, y, z. */
float3(float x, float y, float z);
..
}

Thank you for your help.
Last edited on
Any help with writing the wrapper?
Just saw this videos on YouTuve where someone uses a CPP class in C#.
Maybe it helps.

https://www.youtube.com/watch?v=uEQKcjRXMDE

https://www.youtube.com/watch?v=cqsj__ZVm-c
Last edited on
Topic archived. No new replies allowed.