Passing a object to a cpp function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • solita
    New Member
    • Jun 2009
    • 17

    Passing a object to a cpp function

    I have a C# application.I need to pass a object say a of class A to a function in cpp.The cpp code is compiled to a dll file.
    I need to dllimport and pass the object from c# to cpp where cpp changes the data members of this object and these changes need to be reflected in C#.
    The class I need to pass to cpp function also contain objects of some other classes.

    C#

    [DllImport("My.d ll", EntryPoint = "TestFn", ExactSpelling = false)]
    public static extern void TestFn(ref A a);

    calling in c#

    TestFn(ref a);

    Rightnow I am getting this exception :

    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What does your TestFn method do?

    Comment

    • solita
      New Member
      • Jun 2009
      • 17

      #3
      TestFn will populate some of the members of object a.

      Comment

      Working...