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

C / C++ / MFC

 
Generalchar to integer Pin
12-Dec-01 20:16
suss12-Dec-01 20:16 
GeneralRe: char to integer Pin
NormDroid13-Dec-01 1:54
professionalNormDroid13-Dec-01 1:54 
GeneralRe: char to integer Pin
Tim Smith13-Dec-01 1:59
Tim Smith13-Dec-01 1:59 
GeneralRe: char to integer Pin
NormDroid13-Dec-01 2:39
professionalNormDroid13-Dec-01 2:39 
GeneralRe: char to integer Pin
NormDroid13-Dec-01 2:39
professionalNormDroid13-Dec-01 2:39 
QuestionSystem Idle Time? Pin
12-Dec-01 17:10
suss12-Dec-01 17:10 
AnswerRe: System Idle Time? Pin
Erik Funkenbusch12-Dec-01 17:46
Erik Funkenbusch12-Dec-01 17:46 
GeneralATL Com+ C++ IObjectControl Questions Pin
WhiteKnight12-Dec-01 14:57
WhiteKnight12-Dec-01 14:57 
Now for the c++ dll that will object pool db connection and return a disconnected recordset, I have been attempting to learn on my own with a lot of samples.

The project works fine I believe. Let´s say it runs and I can watch its specifics in the MMC (View Status, Components)
I have run this with and without the IObjectControl Method. I know I have not coded it 100%.

The sample that I am using did not include the events Activate, Deactivate, CanBePooled, it would still object pool (allow me to create instances), but I read:

It is not mandatory for a COM object to implement this interface in order to be pooled. The exception to this rule is if the pooled object also happens to be transactional, in which case the CanBePooled method of the interface is used to determine the state of the resources it holds. If a COM object does not implement IObjectControl, instances of it will be created until the maximum pool size is reached, as each instance is assumed to be poolable.



To see the related changes, you must open the project (Activate, Deactivate, CanBePooled Methods.)
I know that I am not handling the activate, deactivate, canbepooled correctly could you take a look at this part.
I am not evening deactivating the existing code handled it in its own way.




HERE IS A SAMPLE OF WHAT I AM TALKING ABOUT Alan Gordon was the original author of this)


// 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,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();
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);
}




Other changes:
I changed compile info in comsvcs.h
I forced compile to be for win2k. I was getting weird _GetObjectContext errors.
I found on Google an article that told be to force to 2K. What are your thoughts ???

After implementing I was able LINK just fine. I read there is some issue with how win2k platform is identified. ??

//#if (_WIN32_WINNT >= 0x0500)
#define GetObjectContext(ppIOC) (CoGetObjectContext(IID_IObjectContext, (void **) (ppIOC)) == S_OK ? S_OK : CONTEXT_E_NOCONTEXT)
//#else
//extern HRESULT __cdecl GetObjectContext (IObjectContext** ppInstanceContext);
//#endif



3. Provider = MSDAORA.1;Password=wwww;User ID=xxxxx;Data Source=DEV2;Persist Security Info = True;OLE DB SERVICES = -2;


I put a value of OLE DB SERVICES = -2 at the end of my OLEDB Connect string.
Is this the best number to use. I want to just ensure that we are object pooling not resource pooling. I did not wish to use 0 "no services". What are your thoughts?
GeneralCToolBarCtl problem Pin
12-Dec-01 14:25
suss12-Dec-01 14:25 
GeneralCTabCrl question Pin
Dor12-Dec-01 13:49
Dor12-Dec-01 13:49 
GeneralRe: CTabCrl question Pin
PJ Arends15-Dec-01 13:36
professionalPJ Arends15-Dec-01 13:36 
GeneralOpenGL Weirdness Pin
Rick York12-Dec-01 12:41
mveRick York12-Dec-01 12:41 
GeneralRe: OpenGL Weirdness Pin
Rick York13-Dec-01 10:24
mveRick York13-Dec-01 10:24 
GeneralXP visual style, MFC toolbar Pin
scpierre12-Dec-01 11:39
scpierre12-Dec-01 11:39 
QuestionBlending in OpenGL? Pin
12-Dec-01 11:35
suss12-Dec-01 11:35 
AnswerRe: Blending in OpenGL? Pin
Christian Graus12-Dec-01 12:20
protectorChristian Graus12-Dec-01 12:20 
GeneralOther way? Pin
13-Dec-01 16:11
suss13-Dec-01 16:11 
GeneralRe: Other way? Pin
Christian Graus13-Dec-01 16:17
protectorChristian Graus13-Dec-01 16:17 
GeneralRe: Other way? Pin
13-Dec-01 16:58
suss13-Dec-01 16:58 
QuestionHow move a CListCtrl item?! Pin
XAlien12-Dec-01 11:23
XAlien12-Dec-01 11:23 
AnswerRe: How move a CListCtrl item?! Pin
Thomas Blenkers14-Dec-01 0:21
Thomas Blenkers14-Dec-01 0:21 
GeneralOne more question about CreateProcess, etc Pin
12-Dec-01 11:10
suss12-Dec-01 11:10 
GeneralRe: One more question about CreateProcess, etc Pin
Bill Wilson12-Dec-01 13:04
Bill Wilson12-Dec-01 13:04 
GeneralRe: One more question about CreateProcess, etc Pin
13-Dec-01 5:25
suss13-Dec-01 5:25 
GeneralNewbie Image Help Pin
Jerry Wang12-Dec-01 8:50
Jerry Wang12-Dec-01 8:50 

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.