Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting a member variable of a command object within a custom prov

7 views
Skip to first unread message

DanielLue

unread,
Jun 11, 2010, 8:06:09 AM6/11/10
to
Hello,

I have a question concerning my custom OleDb Provider based on the
ATL-templates for C++. My intention is to forward all commands to another
installed OleDb Provider on the machine and to log all SQL-Commands including
the results. To do this, I create a datasource object of another OleDb
Provider (for example Oracle) in the constructor of my own datasource class.
This external datasource object is stored in a member variable of my own
datasource class. In the function "CreateSession" of my datasource class I
call the base implementation of "CreateSession" to get my own session object.
Additionally, I call the "CreateSession" function of the external datasource
object to get an external session to which all the commands received by my
own session object can be forwarded. This external session object should be
stored within my custom session object. Therefore I create a member variable
in my session object, cast the IUnknown pointer received by the CreateSession
function of the base implementation to my session class (wrapped by a
CComPolyObject) and set the member variable of the casted session object to
the address of the external (eg. Oracle) session.

All I have at this point is a datasource object containing an external
datasource object and a session object containing an external session object.
All this works so far, I can connect and query data successfully, but I want
to log the SQL-Commands, so I need to implement my own command object, too.

I then implemented the "CreateCommand" function to achieve this. In this
function, I first call the "CreateCommand" base implementation to get my
custom command object instantiated. Then, I call the "CreateCommand" function
of the external session to have an external command object to which I can
forward the commands. As with the session object, I created a member variable
in the command object to store the external command object. I now cast the
IUnknown pointer to my custom command class (wrapped by a CComPolyObject) and
set the member variable to the external command object.

When I now connect to the OleDb driver with C++, everything works, the
commands are executed and everything is logged. But if I now connect with a
.NET program (C#), the member variable for the external command object in my
custom command object is NULL and the driver doesn't work anymore. The
external session object, however, is set and working. As I debugged the code,
I remarked, that with C++, the instantiated (custom) command object is
wrapped by a CComPolyObject and with C# it is wrapped by a
CComContainedObject. Additionally, by casting the IUnknown pointer (using C#)
to a CComContainedObject I can only access the vftable of the object.

My question is, if this is an known issue or if there is something wrong
with the code and if this is because of the managed/unmanaged differences.

I hope, there is a solution for this.

Thank you for trying to understand my question.

Kind Regards,
Daniel Lütgehetmann

Kenneth A. Larsen

unread,
Jul 9, 2010, 6:30:58 PM7/9/10
to

"DanielLue" <Dani...@discussions.microsoft.com> wrote in message
news:3BA92CEA-E54D-4AFA...@microsoft.com...

Anytime!

0 new messages