Passing enum ref type from C # to C ++ / CLI wrapper in C ++

I searched a lot for the answer but couldn't find it. I have a C ++ / CLI wrapper that connects between my C # and my C ++ code. I would like to pass a pointer to an argument as part of the input parameters of a startup function that will express the status of the program.

In C ++ I have an enum defined: enum statusCode {INIT, BEGIN, CFG_STARTED, CFG_COMPLETED, STAGE1, STAGE2, DONE}

I have the same enum in my C # code:

   public enum statusCode
   {
        INIT, BEGIN, CFG_STARTED, CFG_COMPLETED, STAGE1, STAGE2, DONE
   }

      

I have a run function in C ++ code that gets a pointer to a status: void Run (statusCode * status);

on the c # side i use:

public static statusCode program_status = statusCode.INIT;
wrapper.Run(ref program_status);

      

now in C ++ / CLI interface I am stuck ...

public ref class Wrapper 
{
 public:
 int run(System::String^ outputDir, statusCode% returnStatus);
}

      

in the cpp file:

int CMSWrapper::run(statusCode% returnStatus)
{      
errorCode ret;
   ret = m_Controller->Run( static_cast<statusCode*>(returnStatus)); 
return ret;
}

      

I just can't figure out how to declare the Run function and how to describe it in the shell (CLI / C ++)

+3


source to share


1 answer


You don't need to declare your enum in C ++ / CLI, you only need to declare your enum in a shared assembly referenced by both C # and C ++ / CLI codes, so you can use them in both places.

for example in c # shared.dll



public enum statusCode
{
   INIT, BEGIN, CFG_STARTED, CFG_COMPLETED, STAGE1, STAGE2, DONE
}

      

then reference this shared.dll in both C # and C ++ / CLI projects and use enum as needed

+1


source







All Articles