Works well? You mean by leaking memory?
The caller of the dll needs to be responsible to allocate and clean up memory. The dll can't do it, because if it allocated the memory, it wouldn't know when to free it, so the STANDARD Windows practice is to allocate a buffer in the caller, and pass the buffer and its size to the dll.
Look at any WinApi function that needs to return a string and they all do it by getting passed a buffer and a size.
As I mentioned, see GetComputerName on how to properly declare such a function.
https://docs.microsoft.com/en-us/win...tcomputernamew