Working with WinAPI functions which use C style strings as OUT parameters
问题 Given a WinAPI function which returns it's result via a C style string OUT parameter e.g.: int WINAPI GetWindowTextW( _In_ HWND hWnd, _Out_ LPTSTR lpString, _In_ int nMaxCount ); Is there a better way of using the function than what I'm doing below? HWND handle; // Assume this is initialised to contain a real window handle std::wstring title; wchar_t buffer[512]; GetWindowTextW(handle, buffer, sizeof(buffer)); title = buffer; The above code works, but I have the following issues with it: The