Re: Accessing text / csv files using ADO in C++




"Venkatesh" <Venkatesh@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:281AD548-FAB9-4B99-ACA2-0B003E1B552F@xxxxxxxxxxxxxxxx
Hi Ralph,

Actually I wasn't using an uninitialised object, because soon after the
declaration of spConn you'll find code to CreateInstance that creates an
object. However, I did try what you suggested and this time I got a much
more
informative error "CoInitialize has not been called" instead of "Invalid
pointer" !! I had forgotten to add a call to CoInitialize, so I added it,
and
then I crossed that stage. Then I got a few other errors because of other
problems (such as using a blank user name instead of "Admin"), and when I
solved them, things started working.

So going back, it turns out that the behaviour of:
(1)
_ConnectionPtr spConn;
spConn.CreateInstance(__uuidof(Connection));

is significantly different from that of:
(2)
_ConnectionPtr spConn(__uuidof(Connection));

though internally the constructor called in (2) calls CreateInstance used
in
(1). This difference is because CreateInstance returns hr, so we're
expected
to check it. But the ctor in (2) calls _com_issue_error which internally
does
a throw.

Thanks, Ralph.

Venkatesh


Thanks, for replying and setting me straight on what was actually happening.
I have used the latter construct for so long it became "boilerplate" and I
forgot why I did it that way. <g>

-ralph


.