Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with MSHTML

Status
Not open for further replies.

MihaiFrancu

Programmer
Joined
Jul 23, 2002
Messages
2
Location
RO
I used a component I found on the internet called TIEParser to parse HTML files. The problem appeared when I started doing the parsing in another thread (I made my application multi-threaded). Initially it didn't want to do anything, but after I realised that it didn't even create the interfaces I added the lines CoInitialize(nil) and CoUninitialize. After that it worked, but when I close the application I get a EAccesViolation error in mshtml.dll. I know it's something about COM ojects relasing, but I know very little about COM. Please help me get rid of that error.
The code looks something like this:
procedure TIEParser.Parse(url: string);
var
boolWorking: Boolean;
E: IhtmlElement;
E_IDispatch : IDispatch ;
X, C: Integer;
ConnectionPoint: IConnectionPoint;
OleChar: array[0..MAX_PATH - 1] of TOleChar;
Msg: TMsg;
hr: HRESULT;
begin
CoInitialize(nil);
CoCreateInstance(CLASS_HTMLDocument, nil, CLSCTX_INPROC_SERVER, IHTMLDocument2, Doc);
_Url := @OleChar;
MultibytetoWideChar(CP_ACP, 0, PChar(Url), -1, _Url, sizeof(OleChar));
(Doc as IOleObject).SetClientSite(self as IOleClientsite);
(Doc as IOleControl).OnAmbientPropertyChange(DISPID_AMBIENT_DLCONTROL);
(Doc as IConnectionPointContainer).FindConnectionPoint(IpropertyNotifySink, ConnectionPoint);
ConnectionPoint.Advise(Self as IPropertyNotifySink, C);
HR := LoadUrlFromMoniker;
boolWorking := System.True;
if ((SUCCEEDED(HR)) or (HR = E_PENDING)) then
while (boolWorking and GetMessage(Msg, 0, 0, 0)) do
begin
if ((Msg.Message = WM_USER_STARTWALKING) and (Msg.hWnd = 0)) then
begin
boolWorking := System.False;
All := Doc.Get_all;
end;
end
else
DispatchMessage(Msg);
end;
CoUninitialize;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top