Knowledge Base

BUG: lstrcat, lstrcpy, and lstrcpyn Do Not Set Win32 Error Code on Failure

Article ID: 207008

Article Last Modified on 11/21/2006


APPLIES TO


This article was previously published under Q207008

SYMPTOMS

The GetLastError function returns 0 (zero) when lstrcat, lstrcpy, and lstrcpyn fail.

RESOLUTION

To work around this issue, applications that must run on Windows NT or Windows 2000 should perform error handling based on the return value of the lstrcat, lstrcpy, and lstrcpyn functions, but not on the result of GetLastError.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

The lstrcat, lstrcpy, and lstrcpyn functions should return NULL when they fail. In addition, these functions should set a Win32 error code to be returned by a call to the GetLastError function. Windows 95 and Windows 98 set the error code appropriately. However, Windows NT and Windows 2000 do not set the error code, and therefore GetLastError always returns 0 (ERROR_SUCCESS).

Keywords: kbapi kbbug kbkernbase kbpending kbstring KB207008