0

I'm trying to pass a simple C++ class, created in C#, trough a method to my c++ WinRT component, but I can't figure out how to do that and if its even possible.

I created this custom class in c++ (from https://msdn.microsoft.com/en-us/library/hh441569.aspx)

namespace CppComponent
{
    // Custom struct
    public value struct PlayerData
    {
        Platform::String^ Name;
        int Number;
        double ScoringAverage;
    };

    public ref class Player sealed
    {
    private:
        PlayerData m_player;
    public:
        property PlayerData PlayerStats 
        {
            PlayerData get(){ return m_player; }
            void set(PlayerData data) {m_player = data;}
        }
    };
}

I can create it in c# and play with it, so that works. I can also use other methods that return int or Platform::String.

But how can I use it in methods to c++ like? (and as return type)

in .cpp file:
Platform::String^ CppComponent::DoSomething(Platform::String^ input, Player  myCustomClass)
{

in .h file:
Platform::String^ DoSomething(Platform::String^ input, Player myCustomClass);

Any idea how to get "Player myCustomClass" right?

PS: working on https://github.com/cmusphinx/pocketsphinx-wp-demo

Toine db
  • 709
  • 7
  • 25
  • Q: Are you coding your C++ in C++/CLI, and targeting .Net? In other words, are both your C# projects and C++ projects generating .Net assemblies? – paulsm4 Mar 03 '16 at 08:28
  • @paulsm4 I think not, but I'm not 100% sure what you mean, my code in the c++ component doesn't do anything with .Net. (the most exceptional code part is the platform::vector for collections to return). The only thing I'm looking for is a way to return a custom type; a data object with some strings and ints. – Toine db Mar 03 '16 at 13:05

1 Answers1

0

Turns out I was close already.

I put de struct and class in my .h file and used Player^ instead of Player like:

Platform::String^ CppComponent::DoSomething(Platform::String^ input, Player^ myCustomClass)
Toine db
  • 709
  • 7
  • 25