4 ms·
Lots of win32 API calls work this way ><
by xyzzy123 10y ago
Lots of win32 API calls work this way ><
- mnarayan01 10y agoIIRC, those generally take a pointer to the buffer length, and return an error code and populate the parameter if it's too small.
- xjia 10y agoI remember doing similar things when using ReadProcessMemory https://msdn.microsoft.com/en-us/library/windows/desktop/ms680553(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms6...
- roel_v 10y agoLike which one? Pretty much every single one I know, you pass a buffer and a pointer to a buffer size; the first time you call with buffer NULL and the required buffer size is put in the buffer size; then you allocate the buffer and call again with the proper buffer allocated.
- xyzzy123 10y agoQueryDosDevice? You're right that mostly length is passed back, but esp in libs you get this problem you pass memory you own, some underlying function fails with "buffer too small", but buffer length was not in/out in the interface. Places where this can happen are not always obvious from reading the msdn.
- deleted 10y ago[deleted]
- userbinator 10y agoWin32 actually gives you a way of getting lengths most of the time, like this example: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364934(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/aa3... ... but the corresponding POSIX one doesn't: http://pubs.opengroup.org/onlinepubs/009695399/functions/getcwd.html http://pubs.opengroup.org/onlinepubs/009695399/functions/get... http://insanecoding.blogspot.ca/2007/11/pathmax-simply-isnt.html http://insanecoding.blogspot.ca/2007/11/pathmax-simply-isnt....