🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #1090

Re: TXMLDocument - Access violation

#1090
From: Remy Lebeau (TeamB)
Date: Tue, 03 May 2005 18:18
54 lines
2961 bytes
"nikhil" <nikhilbatooni@yahoo.com> wrote in message
news:42774efe$1@newsgroups.borland.com...

>
Status=MyBrowser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&HTML
Document);

You are not checking to make sure that the Document is actually valid before
trying to access it.

>                 Opt.vt=VT_BSTR; Opt.bstrVal=WideString(SName); //SName is
the generated file name with .txt extension

You are assigning a temporary WideString to the VARIANT.  As soon as that
statement exists, the WideString is freed immediately, leaving the VARIANT
holding on to an invalid BSTR pointer.  You need to keep the WideString in
scope until you are finished using the VARIANT.  Otherwise, don't use a
WideString at all.  Either call SysAllocString() directly and then call
SysFreeString() when you are done with the VARIANT.  Or better yet, don't
use VARIANT at all, but use the VCL's Variant or TVariant class instead.

>                  VARIANT_BOOL __RPC_FAR RetVal;

Get rid of the __RPC_FAR, it has no effect in Win32 programming.

>                 XmlDoc=new TXMLDocument(TName);

Do not do that.  TXMLDocument does not work properly when instantiated
dynamically.  Use the IXMLDocument interface directly, ie:

    _di_IXMLDocument XmlDoc;

    XmlDoc = LoadXMLDocument(TName);
    //...

>                 XmlDoc->Options<<doNodeAutoCreate;
>                 XmlDoc->Options<<doAttrNull;
>                 XmlDoc->Options<<doAutoPrefix;
>                 XmlDoc->Options<<doNamespaceDecl;

You cannot assign Set-based properties like that.  You need to use the '='
operator as well, ie:

    XmlDoc->Options = XmlDoc->Options << doNodeAutoCreate << doAttrNull <<
doAutoPrefix << doNamespaceDecl;

>                 TagName=XmlDoc->DocumentElement->GetNodeName();

You are not checking to make sure that the DocumentElement is actually valid
before trying to access it.


Gambit
Technical Details
Message-ID: <4277c07d$2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!diablo.voicenet.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <427710ee$1@newsgroups.borland.com> <4277208b$3@newsgroups.borland.com> <42774efe$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,5ec60bdd5a7fae56
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.web
References: <427710ee$1@newsgroups.borland.com> <4277208b$3@newsgroups.borland.com> <42774efe$1@newsgroups.borland.com>
Subject: Re: TXMLDocument - Access violation
Date: Tue, 3 May 2005 11:18:07 -0700
Lines: 56
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <4277c07d$2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1115144317 68.69.17.41 (3 May 2005 11:18:37 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!diablo.voicenet.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail