Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just declare use a static string as a default result:</p> <pre><code>TCHAR* GetDirectShowMessageDisplayText( int messageNumber ) { switch( messageNumber ) { // ... default: static TCHAR[] default_value = "This is a default result..."; return default_value; } } </code></pre> <p>You may also declare "default_value" outside of the function.</p> <p>UPDATE:</p> <p>If you want to insert a message number in that string then it won't be thread-safe (if you are using multiple threads). However, the solution for that problem is to use <a href="http://www.boost.org/doc/libs/1_35_0/doc/html/thread/thread_local_storage.html#thread.thread_local_storage.thread_specific_ptr" rel="nofollow noreferrer">thread-specific</a> string. Here is an example using <a href="http://www.boost.org/doc/libs/1_35_0/doc/html/thread.html." rel="nofollow noreferrer">Boost.Thread</a>:</p> <pre><code>#include &lt;cstdio&gt; #include &lt;boost/thread/tss.hpp&gt; #define TCHAR char // This is just because I don't have TCHAR... static void errorMessageCleanup (TCHAR *msg) { delete []msg; } static boost::thread_specific_ptr&lt;TCHAR&gt; errorMsg (errorMessageCleanup); static TCHAR * formatErrorMessage (int number) { static const size_t MSG_MAX_SIZE = 256; if (errorMsg.get () == NULL) errorMsg.reset (new TCHAR [MSG_MAX_SIZE]); snprintf (errorMsg.get (), MSG_MAX_SIZE, "Unexpected notification code (%d)", number); return errorMsg.get (); } int main () { printf ("Message: %s\n", formatErrorMessage (1)); } </code></pre> <p>The only limitation of this solution is that returned string cannot be passed by the client to the other thread.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload