hr = CoCreateInstance(CLSID_DOMDocument, NULL,CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,IID_IXMLDOMDocument, (LPVOID*)&m_piLib);
if (!m_piLib) {
return false;
}
VARIANT_BOOL varOkay;
// VARIANT vXMLSrc,vXMLSrc1;
// VariantInit(&vXMLSrc);
// VariantInit(&vXMLSrc1);
// CFileStream *fs=new CFileStream;
// BSTR bsLP=CString("//存储卡//eGistarXLite//linepatt.htm").AllocSysString();
// BSTR bsLP1=CString("//存储卡//eGistarXLite//save.htm").AllocSysString();
// if (!fs->open(strPathName,true))
// {
// return false;
// }
// vXMLSrc.punkVal = fs;
// vXMLSrc.vt = VT_UNKNOWN;
//vXMLSrc.bstrVal=bsLP;
//vXMLSrc.vt=VT_BSTR;
//vXMLSrc1.bstrVal=bsLP1;
//vXMLSrc1.vt=VT_BSTR;
//m_piLib->load(vXMLSrc,&varOkay);
查询pocketpc2003帮助文件发现loadxml下的一段备注:The loadXML will work only with UTF-16 or UCS-2 encodings;这段话的意思是说明encodings为utf-16,而不是说你一定要在UTF-16下进行编写XML;所以最好不要用visual studio2005中的资源编辑器。你可以用记事本编辑,然后把文件导入到资源中。另外文件头中的必须有<?xml version="1.0" encoding="UTF-16"?>
最后希望在文件结束后添加几个空格;
CeGistarXLiteApp * pApp=(CeGistarXLiteApp*)AfxGetApp();
HMODULE hM = pApp->m_hInstance;
HRSRC hsLP;
HGLOBAL hLP;
char * pLP;
hsLP=::FindResource(hM,MAKEINTRESOURCE(IDR_HTML1),MAKEINTRESOURCE(23));
if (!hsLP) return false;
hLP=LoadResource(hM,hsLP);
pLP=(char *)LockResource(hLP);
BSTR bstr=CString(pLP).AllocSysString();
m_piLib->put_async(VARIANT_FALSE);
m_piLib->loadXML(bstr,&varOkay);
IXMLDOMElement* piLibElt=NULL;
BSTR nodeName;
if (varOkay) {
hr = m_piLib->get_documentElement(&piLibElt);
if (FAILED(hr) || piLibElt == NULL) {
return FALSE;
}
CString strT1,strT2,strT3;
IXMLDOMNodeList *piStyles;
piLibElt->selectNodes(L"*[@name!='']",&piStyles);
IXMLDOMNode *piStyle;
for(piStyles->nextNode(&piStyle);piStyle!=NULL;piStyles->nextNode(&piStyle))
{
piStyle->get_baseName(&nodeName);
strT1=nodeName;
if (strT1=="LinePattern")
{
CGSLLinePattern LP;
LP.Init((IXMLDOMElement *)piStyle);
m_LinePatterns.push_back(LP);
}
}
}