0

I am so sorry for the question that sounds so stupid :)

I have such line of code:

namespace Messages{
/// @brief Interface to support building a message during decoding.
class ValueMessageBuilder : public Common::Logger
....

And I can not use ValueMessageBuilder from my c# project because of this error:

Cannot access internal struct 'ValueMessageBuilder' here.

So I've tried to make it public and recompile dll:

public class ValueMessageBuilder : public Common::Logger

But compilation failed with such error Error C3381: 'QuickFAST::Messages::ValueMessageBuilder' : assembly access specifiers are only available in code compiled with a /clr option F:\Oleg\quickfast_1_4_0_my\src\Messages\ValueMessageBuilder.h 17 1 QuickF‌​AST

So the question is how to convert internal ValueMessageBuilder structure to public?

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
Oleg Vazhnev
  • 23,239
  • 54
  • 171
  • 305

2 Answers2

0

As the error states your code must be compiled with /clr option (Project properties | General | Common Language Runtime Support). after that your project will become c++/clr (managed c++). Also I think the class should be preceded with ref keyword to be visible in c#.

Mohammad
  • 1,253
  • 1
  • 10
  • 26
0

For a class to be usable from C#, it needs to be a managed type with .NET metadata.

Use either ref class or value class.

Note that an object can't contain both managed and native class types. However, a native class can hold a handle to a managed instance (use gcroot) and a managed type can hold a pointer to a native object (My smart pointer, posted on codereview, may help with lifetime management).

Community
  • 1
  • 1
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720