I took the sample program "MultiLangCommandBars" and replaced function "CMultiLangCommandBarsApp::SetLocale" with this code below:
BOOL CMultiLangCommandBarsApp::SetLocale(LCID Locale, LPCTSTR szLocale, LPCTSTR szFileName, BOOL bIsRTL) { if (szFileName) { if (CXTPPropExchangeXMLNode::IsXMLSupported()) // Try to load from XML. Needs IE 4.0 // installed { CString strPath; VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, strPath.GetBufferSetLength(_MAX_PATH), _MAX_PATH)); strPath.ReleaseBuffer();
int nIndex = strPath.ReverseFind(_T('\\')); if (nIndex > 0) strPath = strPath.Left(nIndex + 1); else strPath.Empty();
strPath = strPath + _T("Translations\\") + szFileName + _T(".xml");
// My code changes are bolded below: CString sResXML = L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<resource CompactMode=\"1\" Language=\"German (Germany)\" LANGID=\"1031\">\n" "<string id=\"57670\" value=\"Zeigt Hilfe zum aktuellen Vorgang oder Befehl an.\\nHilfe\"/>\n" "<string id=\"57664\" value=\"Programminformationen, Versionsnummer und Urheberrechte anzeigen\\nDie Info\"/>\n" "<string id=\"57607\" value=\"Drucken des aktiven Dokuments\\nDrucken\"/>\n" "<string id=\"57669\" value=\"Anzeigen der Hilfe für Schaltflächen, Menüs und Fenster, die angeklickt wurden\\nHilfe\"/>\n" "</resource>";
CXTPPropExchangeXMLNode xtpXMLNode(TRUE, NULL, L"resource"); xtpXMLNode.LoadFromString(sResXML); CXTPResourceManager* pResMgr = XTPResourceManager(); if (pResMgr) { // commented out code below works. //CString strPath(_T("c:\\temp\\MultiLangCommandBars.ResourceDe.xml")); //CXTPResourceManagerXML* p = new CXTPResourceManagerXML(strPath); //XTPResourceManager()->SetResourceManager(p);
// Code below has errors later in our code as resource id pResMgr->SetResourceManager(new CXTPResourceManagerXML(&xtpXMLNode)); }
//if (!XTPResourceManager()->SetResourceManager(new CXTPResourceManagerXML(strPath))) // return FALSE; } else { CString strPath; VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, strPath.GetBufferSetLength(_MAX_PATH), _MAX_PATH)); strPath.ReleaseBuffer();
int nIndex = strPath.ReverseFind(_T('\\')); if (nIndex > 0) strPath = strPath.Left(nIndex + 1); else strPath.Empty();
strPath = strPath + _T("Translations\\") + szFileName + _T(".dll");
XTPResourceManager()->SetResourceManager(new CXTPResourceManager()); XTPResourceManager()->SetResourceFile(strPath); } } else { if (!XTPResourceManager()->SetResourceManager(new CXTPResourceManager())) return FALSE; }
::SetThreadLocale(MAKELCID(Locale, SORT_DEFAULT)); ::_tsetlocale(LC_ALL, szLocale);
m_curLanguage = Locale; SetRTLLayout(bIsRTL); ReloadDefaultMenu(); return TRUE; } lpszSection = 0x0000024069d50cd8 L"menu[@id = \"129\"]"
BOOL CXTPPropExchangeXMLNode::IsSectionExists(LPCTSTR lpszSection) { if (!OnBeforeExchange()) return FALSE;
CXTPDOMNodePtr xmlNodePtr;
// Exception is thrown here: HRESULT hr = m_xmlSectionNode->raw_selectSingleNode(CT2BSTR(lpszSection), &xmlNodePtr);
if (FAILED(hr) || xmlNodePtr == NULL) return FALSE;
return TRUE; }
When I run the application I get the exception below:
Exception thrown at 0x00007FFD2D03F2E2 (msxml3.dll) in MultiLangCommandBars.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
CallStack:
> msxml3.dll!Model::Model(struct TLSDATA *,class Object *) Unknown msxml3.dll!OMReadLock::OMReadLock(struct TLSDATA *,class DOMNode *) Unknown msxml3.dll!DOMNode::selectSingleNode(unsigned short *,struct IXMLDOMNode * *) Unknown MultiLangCommandBars.exe!CXTPPropExchangeXMLNode::IsSectionExists(const wchar_t * lpszSection) Line 756 C++ MultiLangCommandBars.exe!CXTPResourceManagerXML::LoadMenuW(CMenu * lpMenu, unsigned int nIDResource) Line 1213 C++ MultiLangCommandBars.exe!CMainFrame::ResetCommandBars() Line 161 C++ MultiLangCommandBars.exe!CMultiLangCommandBarsApp::ReloadDefaultMenu() Line 391 C++ MultiLangCommandBars.exe!CMultiLangCommandBarsApp::SetLocale(unsigned long Locale, const wchar_t * szLocale, const wchar_t * szFileName, int bIsRTL) Line 291 C++ MultiLangCommandBars.exe!CMultiLangCommandBarsApp::OnLanguageGerman() Line 316 C++ MultiLangCommandBars.exe!CMultiLangCommandBarsApp::InitInstance() Line 166 C++ [External Code] MultiLangCommandBars.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 26 C++ [External Code]
Does anyone have an idea's on what is wrong?
Thanks,
|