Use _tcstoul to detect invalid string during unsigned long conversion - unable to treat -ve string as invalid value
<p>I try to use _tcstoul for string to unsigned long conversion.</p>

<p>However, it doesn't treat -ve string input as invalid input. Is there any workaround for this? Or I had missed out something?</p>

<pre><code>#include &lt;cstdio&gt;
#include &lt;tchar.h&gt;

int main() {
    {
        unsigned long iResult(0);
        TCHAR *pszStopString;
        iResult = _tcstoul(_T("2abc"), &amp;pszStopString, 10);
        if( _tcsicmp(pszStopString, _T("")) != 0 ) {
            // OK. We reach here.
            printf("2abc : Error occur during conversion!\n");
        }
    }

    {
        unsigned long iResult(0);
        TCHAR *pszStopString;
        // iResult = 4294967274
        iResult = _tcstoul(_T("-22"), &amp;pszStopString, 10);
        if( _tcsicmp(pszStopString, _T("")) != 0 ) {
            // Nope. We didn't reach here!
            printf("-22 : Error occur during conversion!\n");
        }
    }

    getchar();
}
</code></pre>

<p>I expect during conversion of "-22", error shouldn't occur, as "-22" is a negative value, and I am expecting non-negative value returned from _tcstoul.</p>
