K
K
Kirill H2017-07-30 18:12:54
C++ / C#
Kirill H, 2017-07-30 18:12:54

How to integrate a pure C++ class into a C++/CLI form?

Already asked a question on this topic but did not receive an answer. Now I clarified a little with what exactly I contacted, but I did not find anything on the Internet on this issue during these days.
Source old:

  • Static lib in pure C++
  • C++/CLI form project

Question:
How to declare a class from the library as a field in the form class and initialize it correctly?
How do I do it:
public:
Form()
{
example = new myClass();
}
private:
myClass * example;

Предупреждая все вопросы:
  1. В списке инициализации пробовал, не помогает.
  2. Если попробовать обратится к методам класса в методах формы, тот же ексепшн.
  3. Через "указатель" для C++/CLI — ^ тоже пробовал, вместе с "gcnew", всё тот же результат, менять класс свой в библиотеке под стилистику C++/CLI не буду, класс должен оставаться на чистом C++.

Runtime Exception:
Exception thrown at 0x77D513B9 (ntdll.dll) in App.exe: 0xC0000005: Access violation reading location 0x29AD7B2C.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EkvVN, 2018-03-02
@EkvVN

I also once faced with the need to use a static lib in managed c ++ , there
was a note, maybe it will help:

I figured out this error and found a solution that seems to work
. In my code, in a separate statically linked library (*.lib), there are static class fields
And when the program starts, they are initialized, like all other static and global variables
And when they are initialized at runtime, the program crashes on an assertion in one of the standard files
/*
* If this ASSERT fails, a baf pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
_ASSERTE(_CrtIsValidHeapPointer(pUserData))
Found on the Internet that for the executable CLR project, you need to change the
Linker->Advanced entry point in the Linker properties
Entry Point: main
1) for x32, replace with:
[email protected]@[email protected]@@@Z
2) for x64, replace with:
[email protected]@[email protected]
@@@ Z it has a non-standard form:
int main(int argc, int** argv)
But this one:
int main(array ^args)

----
https://stackoverflow.com/questions/15188757/how-d...
And on the question:
create through new and store a pointer to the class, as in standard C++
C++:
class myClass
{
};

C++/CLI:
public ref class Form : System::Windpows::Forms
{
public:
    Form()
    {
        example = new myClass();
    }
    ~Form()
    {
        delete example;
    }
private:
    myClass * example;
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question