Getting Object Functionality out of C++ code in C#

后端 未结 3 1906
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 22:43

I have have a function in wrote in C++ that calls some functions in a old lib. This function creates some memory makes the calls and destroys the memory. To optimize this I

3条回答
  •  忘掉有多难
    2021-01-14 23:18

    Make a C# class that implements IDisposable. You can wrap a simple C API around your C++ object, so when you construct an instance, it returns a pointer to the C++ class, and when you Dispose() of your C# class, it deletes the pointer.

    You can always dereference this pointer to call methods on your C++ class.

    Another good alternative is to just use C++/CLI to make a wrapper for your C++ class. Handling this type of situation is much simpler there.

提交回复
热议问题