Suppose I have my own class and it is managed. And I want it to contain unmanaged class variables. In this case, it is SYSTEMTIME from winbase.h. I understand that in this case it is necessary to use not a variable, but a pointer, and declare a variable somewhere else. The question is where. If it is static, then you can probably prescribe somewhere once, and if not? If you try to do this in the constructor, the compiler swears. That is, we need a function that creates a variable. And what should this function look like? My class:

ref class MyTime { public: static SYSTEMTIME* currDateAndTimePtr; SYSTEMTIME* setDateAndTimePtr; //... } 

In this case, this option works with static (I have a Windows Forms application, so this is in MainForm_Load ()):

 SYSTEMTIME currDateAndTime; MyTime^ currentTime = gcnew MyTime(); currentTime->currDateAndTimePtr = &currDateAndTime; 

And if in the constructor to write

 MyTime::MyTime() { GetLocalTime(currDateAndTimePtr); } 

then everything works. And if you try to do so

 MyTime::MyTime() { GetLocalTime(currDateAndTimePtr); SYSTEMTIME setDateAndTime; setDateAndTimePtr = &setDateAndTime; } 

it is no longer. What should one do in this situation?

Updating the question: the question with the line above remains in force, that is, I am still interested in the procedure for intersecting the controlled and unmanaged types. But the compiler error was caused by the line GetLocalTime (currDateAndTimePtr); If you replace it with

 SYSTEMTIME tempTime; GetLocalTime(&tempTime); currDateAndTimePtr = &tempTime; 

That error does not appear. The same question, what is the matter?

  • Everything, the question is closed - Matty

0