My code often repeats a fragment:
TCHAR text[10] = {}; Convert(window, id1, text); I want to bring it into a separate function that will return a pointer to text .
TCHAR* Foo(HWND window, int id) { TCHAR *text = new TCHAR[10]; Convert(window, id, text); return text; } When it will be necessary to free the memory, I do not know. Therefore, I used smart pointers:
std::shared_ptr<TCHAR> Foo(HWND window, int id) { std::shared_ptr<TCHAR> text; Convert(window, id, text); //no suitable conversion function from //"std::shared_ptr<TCHAR>" to "TCHAR *" return text; } void Convert(HWND window, int ID, TCHAR* text, int size=10) { HWND handle = GetDlgItem(window, ID); GetWindowText(handle, text, size); } How to allocate memory for 10 elements and solve the problem with the conversion?
Convert(window, id, text.get());. But with memory allocation, this problem will not solve - mymedia