开发者

Why the CString(LPCTSTR lpsz) constructor check the high two bytes of lpsz?

开发者 https://www.devze.com 2023-03-04 20:29 出处:网络
I am reading the source code of CString in MFC. I am very curious about the implementation way of constructor 开发者_运维技巧CString::CString(LPCTSTR lpsz).

I am reading the source code of CString in MFC. I am very curious about the implementation way of constructor 开发者_运维技巧CString::CString(LPCTSTR lpsz).

In my understanding, before copying the string indicated by lpsz, it only needs check whether lpsz is NULL but no need to combine with checking if HIWORD(lpsz) is NULL.

Is any MFC guy passing here and willing to give some explanations?

CString::CString(LPCTSTR lpsz)
{
    Init();
    if (lpsz != NULL && HIWORD(lpsz) == NULL)
    {
        UINT nID = LOWORD((DWORD)lpsz);
        if (!LoadString(nID))
            TRACE1("Warning: implicit LoadString(%u) failed\n", nID);
    }
    else
    {
        int nLen = SafeStrlen(lpsz);
        if (nLen != 0)
        {
            AllocBuffer(nLen);
            memcpy(m_pchData, lpsz, nLen*sizeof(TCHAR));
        }
    }
}


It checks whether it is passed an actual pointer or an integer resource identifier from MAKEINTRESOURCE. In the latter case it loads the string from the resources.


That is for loading a string resource. See the LoadString() call.

0

精彩评论

暂无评论...
验证码 换一张
取 消