none
C++/CLI pointers problem RRS feed

  • Question

  • Imagine I have ref class in C++/CLI project which I use in C# and this class contain c++ pointer

    public ref class objekt { public:

    objekt()

    {

    mObj = new cppObjekt*(nullptr);

    }

    // ... private: cppObjekt ** mObj; // this is must because I can't pass in CLI pointer for C++ method (cppObjekt *& ob) }


    and I create mObj inside c++ dll code for example:

    void create(cppObjekt *& ob)
    {
        cppObjekt * o = new cppObjekt(/* ... */);
        ob = o;
        List.Add(o);
    }

    problem is, program sometimes crash.

    I use wpf for GUI, and when I click add button object is created and everything is fine, but sometimes it crash, under debuger are unknow errros.

    for example

    • Exception thrown at 0x0000000076FFF401 (ntdll.dll) in EFFB GUI.exe: 0xC0000005: Access violation reading location 0x0000000022106A10
    • ntdll.pdb contains the debug information required to find the source for the module ntdll.dll

    or

    • Exception thrown at 0x000007FED79B90BD (wpfgfx_v0400.dll) in EFFB GUI.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
    • wpfgfx_v0400.pdb contains the debug information required to find the source for the module wpfgfx_v0400.dll

    how can I pass pointer from C++/CLI in to C++ dll and hold data both on C++/CLI and dll side without crash?

    EDIT:

    I discover it is not problem in passing pointer, problem is when function create new object and going back to C#. When I use breakpoints, it never crash on creating object inside C++ dll, but when function is back on C#. Sometimes it crash and sometimes not.

    EDIT 2:

    I discover the problem. Problem are in class function pointers which I pass in to another class inside C++ dll.

    It is too late in my time I describe it more tomorow. 

    • Edited by Striebrovlas Thursday, January 24, 2019 12:38 AM problem discovery
    Wednesday, January 23, 2019 10:03 PM

Answers

All replies