Re: about casting
Hello again!
You seems to be very good at COM!
Many thanks again.
I hope you can help me with one small thing.
Here I have the InitRules2 method which is a method defined in the COM
interface ISyntaxObj.
As you can see I save a pointer to my COM interface IHandle_DS* in another
class named CAlterObj.
You can also see that the first method to be called within InitRules2 is
DBInitCommandTemplate.
If you now look at method DBInitCommandTemplate you can see that I use the
local Session and local DS in the previous code in several places
but in the new code I can't use the local Session because of the new
functionality.
I must in some way use the CSession object that is stored in the concrete
C++ class CHandle_DS but that
is not easy because of the COM interface IHandle_DS.
Below I have listed OpenDS. This OpenDS method is part of the IHande_DS COM
interface.
I call this OpenDS from C# asp.net and it works good.
The reason for storing this CDataSource and CSession is to keep the database
open until I close it at the end of C# asp.net
I have also just confirm by testing that I can call OpenDS on the handle_ds
interface pointer from InitRules2 which I mentioned to you was a problem
before but not any longer.
So can you give me some advice how to modify or create a new interface so I
can access the object Session
in method DBInitCommandTemplate see below.
STDMETHODIMP CSyntaxObj::InitRules2(IHandle_DS* handle_ds, BSTR Provider,
BSTR DataSource, BSTR UserId, BSTR Password, BSTR ProductID, BSTR Revision,
BSTR ApplicationID, BSTR ApplicationRev, BSTR SubfileID,
VARIANT_BOOL *bRes)
{
m_pAltObj = new CAlterObj;
m_pAltObj->m_handle_DS = handle_ds;
m_pAltObj->DBInitCommandTemplate(some parameter here)))
}
HRESULT CAlterObj::DBInitCommandTemplate(some parameter here)
{
....
//CSession Session; // old code
//CDataSource DS; // old code
//hr = DS:Open(); // old code
//hr = Session.Open(DS); // old code
hr = sqlRole.Open(Session);
hr = LoadProcedureRules(&Session,&dbPropSet,ProductID, Revision,
SubfileID);
....
}
In header file(h file) for class CAlterObjI have the following
IHandle_DS* m_handle_DS;
STDMETHODIMP Handle_DS::OpenDS(VARIANT_BOOL *bRes)
{
HRESULT hr S_OK;
hr = DS.Open("OraOLEDB.Oracle","IDTHU1","CCR_DTH_USER","P55534552");
hr = Session.Open(DS);
return hr;
}
//Tony
"Giovanni Dicanio" <giovanniDOTdicanio@REMOVEMEgmail.com> wrote in message
news:%23pn9L0yVJHA.2576@TK2MSFTNGP02.phx.gbl...
"Tony Johansson" <johansson.andersson@telia.com> ha scritto nel messaggio
news:uei_k.4614$U5.34467@newsb.telia.net...
From C# asp.net web application I do the following
Handle_DS handle_ds = new Handle_DS()
Yes, and you can do similar things in C++, too:
HandleDS * pHandleDS = new HandleDS();
Unfortunately, COM is more complex.
So I don't define any C-tor for Handle_DS I use the default C-tor.
I never use this CoCreateInstance below for my new class Handle_DS.
hr = CoCreateInstance( CLSID_First_ATL, NULL,
CLSCTX_INPROC_SERVER,
IID_IFirst_ATL, (void**) &IFirstATL);
If you want to instantiate COM components, you can't use C++ operator new.
You can use e.g. CoCreateInstance; instatiation of COM components is not
trivial as for normal C++ classes, there are factory functions involved,
etc.
I know: COM is complex, and this is why it needs proper serious study.
(Frankly speaking, sometimes I really wonder why they invent such a
complex technology...)
Giovanni