Can a C ++ managed assembly return an object in C #?

I am writing a C # application that should read the properties of video video files. The only way I found this is with the Microsoft Media Foundation, which requires C ++.

So far, I have made some progress:

  • I created a C ++ managed assembly that compiles into a DLL.
  • I can name it with a parameter from C # code.
  • It runs and prints the properties of the video file.

What I would like to do next is to return a DLL object of video properties (width, height, duration, etc.). Given that I use managed code in C ++, is there an easy way to determine the type of object and use it to transfer data between C # and C ++, or do I need to use the Marshal class?

+5
source share
2

! ++ ( ++/CLI):

public ref class MyManagedClass{
. . .
}

dll #, , #.

+3

/dll ++ COM Interop, C++/CLI. C++/CLI, /-, #. ++, #, ( ).

++/CLI , CLI, # ( ).

: Quick ++/CLI - ++/CLI 10

: http://msdn.microsoft.com/en-us/magazine/cc163852.aspx

( ), , . Student - ++-, StudentWrapper - CLI-, #:

public ref class StudentWrapper
{
private:
  Student *_stu;
public:
  StudentWrapper(String ^fullname, double gpa)
  {
    _stu = new Student((char *) 
           System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(
           fullname).ToPointer(), 
      gpa);
  }
  ~StudentWrapper()
  {
    delete _stu;
    _stu = 0;
  }

  property String ^Name
  {
    String ^get()
    {
      return gcnew String(_stu->getName());
    }
  }
  property double Gpa
  {
    double get()
    {
      return _stu->getGpa();
    }
  }
};
+2

All Articles