VC的StringTable当中,如何获得String Table中字符串的大小? 我把所有的字符串都放在了VC的String Table当中,但是LoadString最后一个参数要求Buffer的大小.我没用CString,我用std::wstring,那就必须得先resize一下,这样我就不能很正确的设置std::wstring的大小.只能设那么大么?有没有什么别的函数能知道String Table中字符串大小的? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 字符串大小=::LoadString(NULL,ID,NULL,NULL); #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 _AFXDLLint 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 VC的String Table 是什么东西,没听说过 工具栏显示的问题 关于对话框上放ListCtrl出现的问题 DLL中的全局变量。求高手帮助。 关于新手2005的三个问题!100分 CSplitterWnd分割的视图如何随窗口大小调整分割线的位置? 按时间分组查询 哪里有《用TCP/IP进行网际互联》下载? 大家是如何保护自己的软件的? 用什么函数绘画界面效率高呢? 如何使CLISTCTRL的SUBITEM具有编辑功能? m_pHttpFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH, buf, &dwBufSize);并不能得到正确的文件大小 线程内new对象指针,线程退出后,进程delete出错.
#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