全部博文(788)
分类:
2008-11-27 21:16:49
static HRESULT DetectCodePage(
IStreamPtr spStream,
std::vector
DWORD dwFlag = MLDETECTCP_8BIT,
DWORD dwPrefWinCodePage = 0)
{
HRESULT hr = S_OK;
const int N = 32;
INT nScores = N;
DetectEncodingInfo info[N];
hr = DetectCodepageInIStream(
dwFlag,
dwPrefWinCodePage,
spStream,
info,
&nScores);
if (FAILED(hr))
{
return hr;
}
for (int i = 0; i < nScores; i++)
{
dwCodePages.push_back(info[i].nCodePage);
}
return S_OK;
}
// IE5.0 or lator
static HRESULT DetectCodepageInIStream(
DWORD dwFlag,
DWORD dwPrefWinCodePage,
IStream *pstmIn,
DetectEncodingInfo *lpEncoding,
INT *pnScores)
{
HRESULT hr = S_OK;
try
{
IMultiLanguage2Ptr spMultiLanguage2 = GetMultiLanguage();
if (spMultiLanguage2 == NULL)
{
return E_FAIL;
}
这个是调用浏览器的spMultiLanguage2接口的一个方法DetectCodepageInIStream
hr = spMultiLanguage2->DetectCodepageInIStream(
dwFlag,
dwPrefWinCodePage,
pstmIn,
lpEncoding,
pnScores);
if (FAILED(hr))
{
return hr;
}
}
catch (...)
{
return E_FAIL;
}
return S_OK;
}
static IMultiLanguagePtr GetMultiLanguage()
{
HRESULT hr = S_OK;
IMultiLanguagePtr spMultiLanguage;
hr = spMultiLanguage.CreateInstance(__uuidof(CMultiLanguage));
if (FAILED(hr))
{
return NULL;
}
return spMultiLanguage;
}