D
diddy
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure DoParse(ss: TStream);<br>var<br> initDone: Boolean;<br> htmlDoc: IHTMLDocument2;<br> pPersist: IPersistStreamInit;<br> pMS: IMarkupServices;<br> pMkStart: IMarkupPointer;<br> pMkFinish: IMarkupPointer;<br> pMC: IMarkupContainer;<br> pDoc: IHTMLDocument2;<br> stream: TStringStream;<br> sHTML: WideString;<br>begin<br> stream := nil;<br> initDone := Succeeded(CoInitialize(nil));<br> if not initDone then Exit;<br> try<br> stream := TStringStream.Create('');<br> stream.CopyFrom(ss, ss.Size);<br> if (stream.Size <= 0) then raise Exception.Create('MemoryStream create failed!');<br> sHTML := stream.DataString;<br> CoCreateInstance(CLASS_HTMLDocument,<br> nil,<br> CLSCTX_INPROC_SERVER,<br> IID_IHTMLDocument2,<br> htmlDoc);<br> if Assigned(htmlDoc) then begin<br> htmlDoc.QueryInterface(IID_IPersistStreamInit, pPersist);<br> if Assigned(pPersist) then begin<br> pPersist.InitNew;<br> pPersist._Release;<br> htmlDoc.QueryInterface(IID_IMarkupServices, pMS);<br> if Assigned(pMS) then begin<br> pMS.CreateMarkupPointer(pMkStart);<br> pMS.CreateMarkupPointer(pMkFinish);<br> pMS.ParseString(Word(sHTML[1]), 0, pMC, pMkStart, pMkFinish);<br> if Assigned(pMC) then begin<br> pMC.QueryInterface(IID_IHTMLDocument2, pDoc);<br> if Assigned(pDoc) then begin<br> ////////////////////////////////<br> // and now,take my job -- search keyword<br> //ParseDocument(pDoc);<br> pDoc._Release;<br> end;<br> pMC._Release;<br> end;<br> if (pMkStart <> nil) then pMkStart._Release;<br> if (pMkFinish <> nil) then pMkFinish._Release;<br> pMS._Release;<br> end;<br> pPersist._Release;<br> pPersist._Release;<br> end;<br> htmlDoc._Release;<br> end;<br> finally<br> if Assigned(stream) then Freeandnil(stream);<br> if initDone then CoUninitialize;<br> end;<br>end;<br><br>// 多次执行DoParse之后,就出内存死锁啦,代码是从VC源码里翻译过来的,不知道那里不妥当,累死我了