以前,KB2465367 などの影響を受けたが,その対応版 KB2538218 のコードの抜粋
typedef BOOL (WINAPI *PFNFINDACTCTXSECTIONSTRING)(DWORD, const GUID *, ULONG, LPCTSTR, PACTCTX_SECTION_KEYED_DATA);
static HINSTANCE _AfxLoadLangDLL(LPCTSTR pszFormat, LPCTSTR pszPath, LCID lcid)
{
TCHAR szLangDLL[_MAX_PATH+14];
TCHAR szLangCode[4];
HINSTANCE hInstance = NULL;
if (lcid == LOCALE_SYSTEM_DEFAULT) {
Checked::tcscpy_s(szLangCode, _countof(szLangCode), _T("LOC"));
}
else {
int nResult;
nResult = ::GetLocaleInfo(lcid, LOCALE_SABBREVLANGNAME, szLangCode, 4);
if (nResult == 0)
return NULL;
ASSERT( nResult == 4 );
}
int ret;
ATL_CRT_ERRORCHECK_SPRINTF(ret = _sntprintf_s(szLangDLL,_countof(szLangDLL),_countof(szLangDLL)-1,pszFormat,pszPath,szLangCode));
if(ret == -1 || ret >= _countof(szLangDLL)) {
ASSERT(FALSE);
return NULL;
}
TCHAR *pszFilename = ::PathFindFileName(szLangDLL);
ACTCTX_SECTION_KEYED_DATA data = {sizeof(data)};
HMODULE hKernel = GetModuleHandle(_T("KERNEL32"));
PFNFINDACTCTXSECTIONSTRING pfnFindActCtxSectionString = NULL;
if (hKernel != NULL) {
#ifdef _UNICODE
pfnFindActCtxSectionString = (PFNFINDACTCTXSECTIONSTRING)GetProcAddress(hKernel, "FindActCtxSectionStringW");
#else
pfnFindActCtxSectionString = (PFNFINDACTCTXSECTIONSTRING)GetProcAddress(hKernel, "FindActCtxSectionStringA");
#endif
}
if (pfnFindActCtxSectionString &&
pfnFindActCtxSectionString(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, pszFilename, &data)) {
// Load using the dll name only…
hInstance = ::LoadLibraryEx(pszFilename, NULL, 0);
}
else {
// Load using the full path…
hInstance = ::LoadLibraryEx(szLangDLL, NULL, 0);
}
return hInstance;
}