Click here to Skip to main content
15,892,809 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow get the full path of a process? Pin
Wing of Angel21-Dec-01 6:50
Wing of Angel21-Dec-01 6:50 
AnswerRe: how get the full path of a process? Pin
Ravi Bhavnani21-Dec-01 7:34
professionalRavi Bhavnani21-Dec-01 7:34 
GeneralRe: how get the full path of a process? Pin
Wing of Angel22-Dec-01 2:35
Wing of Angel22-Dec-01 2:35 
Generallistview: highlight whole column Pin
kasturirawat21-Dec-01 6:28
kasturirawat21-Dec-01 6:28 
GeneralRe: listview: highlight whole column Pin
Michael Dunn21-Dec-01 6:29
sitebuilderMichael Dunn21-Dec-01 6:29 
GeneralRe: listview: highlight whole column Pin
kasturirawat21-Dec-01 6:41
kasturirawat21-Dec-01 6:41 
GeneralRe: listview: highlight whole column Pin
Michael Dunn21-Dec-01 13:22
sitebuilderMichael Dunn21-Dec-01 13:22 
GeneralQuestion.. IObjectControl Pin
WhiteKnight21-Dec-01 6:01
WhiteKnight21-Dec-01 6:01 
I am using this component to retrieve disconnected recordsets to an ASP or VB client. I pass in a SQL Statement and return the disconnected Recordset.
Under COM+ Component Services, I created and application and set the following properties: Object Pooling, IObjectConstruction, JITA, Transactions are set to NOT Supported. I do not plan on using transactions in my project.

The Example I followed (Alan Gordon's) to build this DID NOT include the IObjectControl Interface.
I added, you can see that its references are commented out. (The component runs fine with and w/o the IObjectControl declares.
The component appears to function properly. Of course it has not really been stress tested.

My question to you is??? Is this properly coded?? I read in Tim Ewald's Transactional COM+, that you must use IObjectControl if you are using ObjectPooling and JITA.
Is this true? Could you take a quick look over this and give me your opinion? How would you code this differently to ensure that IObjectControl is being used properly with ObjectPooling and JITA. If you need to see the whole project, I can send it to you zipped.

Happy Holidays !!

Sincerely,

Peter J. Santiago
www.whiteknightinc.com



// Book.cpp : Implementation of CBook
#include "stdafx.h"
#include "Articleproject.h"
#include "Book.h"
const E_CONFIGURATION=MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,0x200+108);
const E_CONFLICTS_FOUND=MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,0x200+109);
const int conTitleFieldLength=80;
#undef EOF
/////////////////////////////////////////////////////////////////////////////
// CBook

//HRESULT CBook::Activate()
//{
// HRESULT hr = GetObjectContext(&m_spObjectContext);
// if (SUCCEEDED(hr))
// return S_OK;
//return hr;
//}

//BOOL CBook::CanBePooled()
//{
// return TRUE;
//}

//void CBook::Deactivate()
//{
// m_spObjectContext.Release();
//}


STDMETHODIMP CBook::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IBook
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (::ATL::InlineIsEqualGUID(*arr[i],riid)) // pjs added
return S_OK;
}
return S_FALSE;
}


STDMETHODIMP CBook::RetrieveByID(BSTR id, _Recordset **rs)
{
_bstr_t strDescription;
HRESULT hRetval;
_ConnectionPtr pConn;
_RecordsetPtr pRS;
IContextState *pContextState=NULL;

if (0==mConnectionString.length())
{
hRetval=E_CONFIGURATION;
strDescription=L"You must configure a connection string";
goto exit_cleanup;
}
hRetval=CoGetObjectContext(IID_IContextState,(void **)&pContextState);
if (SUCCEEDED(hRetval))
{


// NEW WAY PJS 12/8/2001 TO PASS IN SQL STMT AND CREATE AN DISCONN RECORDSET
_bstr_t sql(id);

try
{

// Create and Open the Connection PJS
pConn.CreateInstance( __uuidof(Connection));
pConn->Open(mConnectionString, "", "",-1);

// Create and Open the Recordset PJS
pRS.CreateInstance( __uuidof(Recordset));
pRS->CursorLocation=adUseClient;
pRS->Open(sql,pConn.GetInterfacePtr(),adOpenStatic,adLockBatchOptimistic,-1);
pRS->AddRef();
*rs=pRS;
pRS->PutRefActiveConnection(NULL);

}
catch ( _com_error err)
{
strDescription=err.Description();
// PJS
hRetval=err.Error();
}
}
else
{
_com_error err(hRetval);

strDescription=
L"Your component may not be" \
L" configured";
}


// Exit and cleanup code
exit_cleanup:
if (NULL != pContextState)
{
if (SUCCEEDED(hRetval))
pContextState->SetMyTransactionVote(TxCommit);
else
pContextState->SetMyTransactionVote(TxAbort);

pContextState->SetDeactivateOnReturn(VARIANT_TRUE);
pContextState->Release();
}
if (NULL != pConn)
{
if (adStateOpen==pConn->GetState())
pConn->Close();
pConn=NULL;
}
if (SUCCEEDED(hRetval))
return hRetval;

else
return Error((LPOLESTR)strDescription,IID_IBook,hRetval);
}




// Book.h : Declaration of the CBook

#ifndef __BOOK_H_
#define __BOOK_H_

#include "resource.h" // main symbols

/////////////////////////////////////////////////////////////////////////////
// CBook
class ATL_NO_VTABLE CBook :
public CComObjectRootEx<ccommultithreadmodel>,
public CComCoClass<cbook, &clsid_book="">,
// public IObjectControl,
public ISupportErrorInfo,
public IDispatchImpl<ibook, &iid_ibook,="" &libid_articleprojectlib="">,
public IObjectConstruct
{
public:
CBook()
{
}

DECLARE_REGISTRY_RESOURCEID(IDR_BOOK)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CBook)
COM_INTERFACE_ENTRY(IBook)
COM_INTERFACE_ENTRY(IObjectConstruct)
// COM_INTERFACE_ENTRY(IObjectControl)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);


// IObjectControl
// public:
// STDMETHOD(Activate)();
// STDMETHOD_(BOOL, CanBePooled)();
// STDMETHOD_(void, Deactivate)();

// CComPtr<iobjectcontext> m_spObjectContext;

// IBook
public:
STDMETHOD(xStr)(/*[out, retval]*/ BSTR* returnval);
STDMETHOD(RetrieveByID)(/*[in]*/ BSTR id,/*[out,retval]*/ _Recordset** rs);

STDMETHOD(Construct) (IDispatch *pCtorObj)

{
_bstr_t strDescription;
HRESULT hRetval;
IObjectConstructString *pStr;
BSTR strConstruct;
if (pCtorObj != NULL)
{

hRetval=pCtorObj->QueryInterface(IID_IObjectConstructString,(void **)&pStr);
if (SUCCEEDED(hRetval))
{
hRetval=pStr->get_ConstructString(&strConstruct);
if (SUCCEEDED(hRetval))
{
mConnectionString=strConstruct;
SysFreeString(strConstruct);
}
pStr->Release();
}
elsentabitab pConn->Open(mConnectionStri pConn->Open(mConnection
{
_com_error err(hRetval);
strDescription=err.Description();
ATLTRACE(err.ErrorMessage());
}
}
else
{
hRetval=E_POINTER;
strDescription=L"An invalid pointer was passed to Construct";
}
if (S_OK==hRetval)
return hRetval;
else
return Error((LPOLESTR)strDescription,IID_IBook,hRetval);
}
private:
_bstr_t mConnectionString;
};

#endif //__BOOK_H_
Questionok dumb, but... how do i make the code look orange? Pin
Kuniva21-Dec-01 3:06
Kuniva21-Dec-01 3:06 
AnswerRe: ok dumb, but... how do i make the code look orange? Pin
Simon Walton21-Dec-01 3:09
Simon Walton21-Dec-01 3:09 
GeneralRe: ok dumb, but... how do i make the code look orange? Pin
Kuniva21-Dec-01 3:20
Kuniva21-Dec-01 3:20 
QuestionHow to save a great deal of binary data into database? Pin
white jungle21-Dec-01 0:58
white jungle21-Dec-01 0:58 
AnswerRe: How to save a great deal of binary data into database? Pin
Pierre Heler-Caruel21-Dec-01 1:12
Pierre Heler-Caruel21-Dec-01 1:12 
GeneralRe: How to save a great deal of binary data into database? Pin
white jungle21-Dec-01 1:22
white jungle21-Dec-01 1:22 
GeneralRe: How to save a great deal of binary data into database? Pin
Pierre Heler-Caruel21-Dec-01 1:28
Pierre Heler-Caruel21-Dec-01 1:28 
GeneralRe: How to save a great deal of binary data into database? Pin
markkuk21-Dec-01 1:29
markkuk21-Dec-01 1:29 
GeneralProblems scrolling in an edit box Pin
Fredrik Skog21-Dec-01 0:34
Fredrik Skog21-Dec-01 0:34 
GeneralRe: Problems scrolling in an edit box Pin
James R. Twine21-Dec-01 6:34
James R. Twine21-Dec-01 6:34 
GeneralRe: Problems scrolling in an edit box Pin
Fredrik Skog26-Dec-01 20:53
Fredrik Skog26-Dec-01 20:53 
GeneralRe: Problems scrolling in an edit box Pin
James R. Twine27-Dec-01 5:21
James R. Twine27-Dec-01 5:21 
GeneralRe: Problems scrolling in an edit box Pin
Fredrik Skog27-Dec-01 19:59
Fredrik Skog27-Dec-01 19:59 
GeneralRe: Problems scrolling in an edit box Pin
Fredrik Skog27-Dec-01 22:18
Fredrik Skog27-Dec-01 22:18 
GeneralRe: Problems scrolling in an edit box Pin
James R. Twine28-Dec-01 16:11
James R. Twine28-Dec-01 16:11 
GeneralRe: Problems scrolling in an edit box Pin
Fredrik Skog1-Jan-02 23:48
Fredrik Skog1-Jan-02 23:48 
GeneralList of id's in a NetWork Pin
San21-Dec-01 0:16
San21-Dec-01 0:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.