Tuesday, August 01, 2006

The SystemParametersInfo function in Windows CE can be tricky, even deadly, when it comes to passing in buffers for SPI_GETOEMINFO or SPI_GETPLATFORMTYPE. Each of these uiAction values fill a given buffer with a string. The uiParam argument takes the size of that buffer. The catch is, for SPI_GETOEMINFO, uiParam takes a size of buffer in bytes and for SPI_GETPLATFORMTYPE uiParam takes the size of the buffer in count of unicode characters.

The documentation on SPI_GETOEMINFO is not precise on which type of buffer size is requested, and if you pass the wrong one to SPI_GETPLATFORMTYPE, you could find yourself in a buffer overrun situation. Be careful. The code below is safe: