I'm calling C++ method from C# code. Everything works fine except returning multiple parameters back to C#.
In my case those parameters are: int x, y, width, height;
What I want to do is to return a class or struct from c++ code to c#.
I have provided an example so it would be much more clear what is on my mind. I know that one way to go is to use Marshal class, maybe the only way.
C# code
public class ImageMatch
{
    //method that is used to call pass string parameters and call c++ method
    [System.Runtime.InteropServices.DllImport("ImageComputingWrapper.dll", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
    static extern ImageComputingWrapper.ImageParams ComputeImage(string imgPath, string templPath);
    public  GetImgParams(string imgPath, string templPath)
    {
        //a class from C++ code
        ImageComputingWrapper.ImageParams imgParams;
        //retreive all the data
        imgParams = ComputeImage(imgPath, templPath);
    }
}
C++ code
//ImageComputingWrapper.cpp
extern "C" __declspec(dllexport) ImageComputingWrapper::ImageParams ComputeImage(const char* imgPath, const char* templPath)
{
    computeImage* compImage = new computeImage(imgPath, templPath);
    ImageComputingWrapper::ImageParams imageParams;
    imageParams.x = compImage->x;
    imageParams.y = compImage->y;
    imageParams.width = compImage->width;
    imageParams.height = compImage->height;
    return imageParams;
}
//ImageComputingWrapper.h
//class to return back to c#
public ref class ImageParams
{
    public:
        ImageParams(){}
        int x;
        int y;
        int width;
        int height;
};
I do know that it is not possible to return class from C++ code to C# as it's in this example. It is just to easily understand what I meant.
One thing to point out, I am a C# programmer so there may be something wrong in that C++ code (pointers).
 
     
    