getClassInfoFromProgId in DispatchEvents.cpp hard codes abData to 50 bytes. RegQueryValueEx works fine as long as the data read is less than 50 bytes in length. However, if the data is longer, then lval is set to ERROR_MORE_DATA, which means you need to reallocate the buffer and call the function again. This would need to be done in a while loop until RegQueryValueEx returns ERROR_SUCCESS.
My fix was to call it once to find out how much space needs to be allocated. If RegQueryValueEx returns ERROR_SUCCESS and the number of bytes to be allocated is greater than 0, a buffer is allocated and RegQueryValueEx is called again.
I also had to change BSTR bsLibId = A2BSTR((char*)abData); to BSTR bsLibId = W2BSTR((LPCWSTR)abData); On Windows 2003 Server, RegQueryValueEx returns a unicode string in the buffer causing A2BSTR to only convert the first character. W2BSTR converts correctly.
There is however a different fix that could be made, instead of using RegQueryValueEx use RegQueryValueExA, all strings returned are ANSI then use A2BSTR. RegQueryValueExW could also be used, it returns strings in unicode format but then Windows ME/98/95 requires the Microsoft Layer for Unicode.
I was toying with the idea of using boost libraries to handle resource allocation and deallocation but I don't have the time right now. Instead I used goto to ensure that the buffer I malloc'ed would be freed before the function exited.
Log in to post a comment.