3

I have searched a lot for an answer but could not find one. 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 as the input parameters of the run function which 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 the c++ code that gets the pointer to the status: void Run(statusCode* status);

in the C# side I am using:

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

now in the 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 cant figure out how to declare the Run function and how to describe it in the wrapper (CLI/C++)

Garry
  • 4,996
  • 5
  • 32
  • 44
  • Chicken-and-egg, declare the enum in your C++/CLI code instead. Use `public enum class StatusCode { Init, Begin, ... }; – Hans Passant May 22 '15 at 06:42

1 Answers1

1

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, that way you'd be able to use it 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 the enum as you need it

Eugenio Miró
  • 2,398
  • 2
  • 28
  • 38