I created a function that converts all event notification codes into strings. Pretty simple stuff.
I have a bunch of constants like
const _bstr_t DIRECTSHOW_MSG_EC_ACTIVATE("A video window is being activated or deactivated."); const _bstr_t DIRECTSHOW_MSG_EC_BUFFERING_DATA("The graph is buffering data, or has stopped buffering data."); const _bstr_t DIRECTSHOW_MSG_EC_BUILT("Send by the Video Control when a graph has been built. Not forwarded to applications."); .... etc....
and my function
TCHAR* GetDirectShowMessageDisplayText( int messageNumber ) { switch( messageNumber ) { case EC_ACTIVATE: return DIRECTSHOW_MSG_EC_ACTIVATE; case EC_BUFFERING_DATA: return DIRECTSHOW_MSG_EC_BUFFERING_DATA; case EC_BUILT: return DIRECTSHOW_MSG_EC_BUILT; ... etc ...
No big deal. They took me 5 minutes to throw together.
... but I just donβt believe that I have all the possible values, so I want the default to return something like "Unexpected notification code (7410)" if no matches are found.
Unfortunately, I cannot think of returning a valid pointer without forcing the caller to delete the memory line ... which is not only unpleasant, but also contrary to the simplicity of the other returned values.
Therefore, I can not think of any way to do this without changing the return value to the parameter that the user passes to the buffer and the length of the string. What would my function look like
BOOL GetDirectShowMessageDisplayText( int messageNumber, TCHAR* outBuffer, int bufferLength ) { ... etc ...
I really don't want to do this. There must be a better way.
Whether there is a?
I am returning to C ++ after a 10-year hiatus, so if this is something obvious, don't reduce that I missed it for some reason.