Due to upgrading a certain program to VS .Net 2005, parts of the existing codebase stopped working - no crashes, but some windows API calls now fail.
The problem has been reduced to code as the following:
String retrieveObjectProperty(); /*...*/ SomeWindowsCall( ..., retrieveObjectProperty().getInternalString(), ... );
The String object returned by the inner property query method houses its own dynamically allocated storage (dynamic C-style char* array).
Obviously, calling retrieveObjectProperty() creates a copy of the internal string on the stack for return. Now, getInternalString() retrieves the internal character sequence representation of that temporary object and passes it on to the OS.
The problem now, I think, is that the string itself is destroyed before the API call actually is performed, and thus, the internal char* is deleted as well.
Does anybody know what the standard has to say in that matter ?
When are destructors called for temporary objects within expressions of some kind ?
Thank you for your input :)