This still misses the point. The issue was how to transfer such a string at all. It seems it's not possible with LibraryLink. "Writing a custom function" must still rely on the LibraryLink API. If it is possible to write such a custom function, that would solve the problem. But I don't see how to use the LibraryLink API to do this. If you see a way, can you elaborate?
I am aware that the MathLink API does support strings with null bytes and that it can be used in LibraryLink code at the cost of some complexity and performance. It seems this is the way to go.
One difficulty with using LibraryLink is that it is not fully documented, so sometimes I'm not sure if something is not possible or just not well documented. I see in the header files that there were many additions to the API in v9, but not all are described in the documentation.