我把所有的字符串都放在了VC的String Table当中,但是LoadString最后一个参数要求Buffer的大小.我没用CString,我用std::wstring,那就必须得先resize一下,这样我就不能很正确的设置std::wstring的大小.只能设那么大么?有没有什么别的函数能知道String Table中字符串大小的?

解决方案 »

  1.   

    字符串大小=::LoadString(NULL,ID,NULL,NULL);
      

  2.   

    #ifdef _UNICODE
    #define CHAR_FUDGE 1    // one TCHAR unused is good enough
    #else
    #define CHAR_FUDGE 2    // two BYTES unused for case of DBC last char
    #endifBOOL CString::LoadString(UINT nID)
    {
        // try fixed buffer first (to avoid wasting space in the heap)
        TCHAR szTemp[256];
        int nLen = AfxLoadString(nID, szTemp, _countof(szTemp));
        if (_countof(szTemp) - nLen > CHAR_FUDGE)
        {
            *this = szTemp;
            return nLen > 0;
        }    // try buffer size of 512, then larger size until entire string is retrieved
        // 先按照256尝试,不行就再增加256,直到可以装下
        int nSize = 256;
        do
        {
            nSize += 256;
            nLen = AfxLoadString(nID, GetBuffer(nSize-1), nSize);
        } while (nSize - nLen <= CHAR_FUDGE);
        ReleaseBuffer();    return nLen > 0;
    }#ifndef _AFXDLL
    int AFXAPI AfxLoadString(UINT nID, LPTSTR lpszBuf, UINT nMaxBuf)
    {
        ASSERT(AfxIsValidAddress(lpszBuf, nMaxBuf*sizeof(TCHAR)));
    #ifdef _DEBUG
        // LoadString without annoying warning from the Debug kernel if the
        //  segment containing the string is not present
        if (::FindResource(AfxGetResourceHandle(),
           MAKEINTRESOURCE((nID>>4)+1), RT_STRING) == NULL)
        {
            lpszBuf[0] = '\0';
            return 0; // not found
        }
    #endif //_DEBUG
        int nLen = ::LoadString(AfxGetResourceHandle(), nID, lpszBuf, nMaxBuf);
        if (nLen == 0)
            lpszBuf[0] = '\0';
        return nLen;
    }
    #endif
      

  3.   

    VC的String Table 是什么东西,没听说过