Click here to Skip to main content
16,005,467 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: I want to export global data in a DLL Pin
KaЯl9-Dec-03 7:00
KaЯl9-Dec-03 7:00 
GeneralRe: I want to export global data in a DLL Pin
Matthew Busche9-Dec-03 8:42
Matthew Busche9-Dec-03 8:42 
GeneralRe: I want to export global data in a DLL Pin
KaЯl9-Dec-03 9:38
KaЯl9-Dec-03 9:38 
GeneralRe: I want to export global data in a DLL Pin
Alexander M.,9-Dec-03 4:53
Alexander M.,9-Dec-03 4:53 
GeneralRe: I want to export global data in a DLL Pin
Matthew Busche9-Dec-03 6:24
Matthew Busche9-Dec-03 6:24 
QuestionAny way out......??? Pin
satadru9-Dec-03 0:51
satadru9-Dec-03 0:51 
AnswerRe: Any way out......??? Pin
Shanmuga Sundar9-Dec-03 1:56
Shanmuga Sundar9-Dec-03 1:56 
GeneralFirst-chance exception in GH_DBM_COMDLL_Stub_MFC_EXE.exe: 0xC0000005: Access Violation Pin
derik_konark9-Dec-03 0:39
derik_konark9-Dec-03 0:39 
MY DLL CODE : CDBMgrClass is a generic class got added to the
DLL workspace for IGenericDBManager Interface.

I am calling my interface standard method i.e. STDMETHODIMP CGenericDBManager::Fetch(BSTR bstrSELECTSQLString, _Recordset **pFetchRecordset, BSTR *bstrFetchErrDesc, LPDISPATCH *ppVal)
from my stub in VC++(MFC). But the stub returns the OxThe thread 0x388 has exited with code 0 (0x0).

First-chance exception in GH_DBM_COMDLL_Stub_MFC_EXE.exe: 0xC0000005: Access Violation.
First-chance exception in GH_DBM_COMDLL_Stub_MFC_EXE.exe: 0xC0000005: Access Violation.

Below the DLL code : The STDMETHODIMP calls internally CDBMgrClass::ExecuteFetchQuery()

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Name : ExecuteFetchQuery()
// Description : It does the EXECUTE of the FETCH SQL COMMAND
// Return Value : _RecordsetPtr
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
_RecordsetPtr CDBMgrClass::ExecuteFetchQuery(char* sqlstring)
{
HRESULT hr = S_OK;
try
{
IsConnected();
m_csDatabaseOpLock.Lock();
TESTHR(m_pCommand.CreateInstance(__uuidof(Command)));
TESTHR(m_pRecordset.CreateInstance(__uuidof(Recordset)));
TESTHR(m_pParameter.CreateInstance(__uuidof(Parameter)));
m_pCommand->ActiveConnection = m_pConnObj;
m_pCommand->CommandText = sqlstring;
m_pCommand->CommandType = adCmdText;
m_pRecordset = m_pCommand->Execute(NULL, NULL, adCmdText);
m_pConnObj->Close();


}
catch(CException exception)
{
// Handle the exception here.
// "exception" contains information about the MFC DB exception.

TCHAR szCause[255];
EString strFormatted;
exception.GetErrorMessage(szCause, 255);
strFormatted = _T("The Error: ");
strFormatted += szCause;
OutputDebugString(strFormatted.c_str());
m_bIsConnected = FAILURE;
m_pRecordset = NULL;
}
catch(_com_error &e)
{
hr = e.Error();
_bstr_t bstrError = e.Description();
OutputDebugString(bstrError);
m_bIsConnected = FAILURE;
m_pRecordset = NULL;
}
catch(...)
{

}

m_csDatabaseOpLock.Unlock();
return m_pRecordset;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Name : Fetch
// Description : Interface Public Method
// Input : /*[in]*/BSTR bstrSELECTSQLString
// Output : /*[out]*/_Recordset **pFetchRecordset, /*[out]*/BSTR *bstrFetchErrDesc,/*[out]*/LPDISPATCH *ppVal
// Return Value : S_OK or E_FAIL
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CGenericDBManager::Fetch(BSTR bstrSELECTSQLString, _Recordset **pFetchRecordset, BSTR *bstrFetchErrDesc, LPDISPATCH *ppVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())

USES_CONVERSION;

CoInitialize(NULL);
HRESULT hr = S_OK;
CDBMgrClass* pDBMgrClass = NULL;
_RecordsetPtr m_pRecord_Set(__uuidof(Recordset));
m_pRecord_Set = NULL;
pFetchRecordset = NULL;

try
{
pDBMgrClass = new CDBMgrClass();
if(pDBMgrClass)
{
_bstr_t _bstrFetchQuery(bstrSELECTSQLString);
m_pRecord_Set = pDBMgrClass->ExecuteFetchQuery(_bstrFetchQuery.operator char*());
if(m_pRecord_Set)
*pFetchRecordset = m_pRecord_Set;
m_pRecord_Set->QueryInterface(IID_IDispatch,(void**) &ppVal);
m_pRecord_Set->Close();
}
else
{
EString strFormatted;
strFormatted = _T("\nGHDER Database Fetch Error\n");
_bstr_t _bstrFetchErrorString(_T(strFormatted.c_str()));
*bstrFetchErrDesc = _bstrFetchErrorString.operator wchar_t*();
delete pDBMgrClass;
}

// Clean up objects before exit
bstrFetchErrDesc = NULL;
delete pDBMgrClass;
}
catch(CException exception)
{
// Handle the exception here.
// "exception" contains information about the MFC DB exception.
TCHAR szCause[255];
EString strFormatted;
exception.GetErrorMessage(szCause, 255);
strFormatted = _T("The Error: ");
strFormatted += szCause;

_bstr_t _bstrFetchErrorString(_T(strFormatted.c_str()));
*bstrFetchErrDesc = _bstrFetchErrorString.operator wchar_t*();

delete pDBMgrClass;
hr = E_FAIL;
}
catch ( _com_error &e )
{
_bstr_t bstrError = e.Description();
_variant_t tErr(e.Error());
_bstr_t tMsg("IGenericDBManager::Fetch::=" );
tMsg += "::Error::";
tMsg += (_bstr_t) tErr;

*bstrFetchErrDesc = tMsg.operator wchar_t*();
delete pDBMgrClass;
hr = E_FAIL;
}
catch(...)
{

}

CoUninitialize();
return hr;
}

///////////////////////////////////////////////////////////////////////

STUB CALLER>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//////////////////////////////////////////////////////////////////////

void CGH_DBM_COMDLL_Stub_MFC_EXEDlg::OnFetch()
{

HRESULT hr = S_OK;

USES_CONVERSION;

BSTR *pbstrFetchErrString = NULL;
_RecordsetPtr pRecordset = NULL;
IGenericDBManager *pGenericDBManager = NULL;
BSTR bstrSELECTSQLQuery;

//FORM THE SQL QUERY FOR ANY TABLE
_bstr_t _bstrSELECTSQLString = (_T("SELECT * FROM GHDR1TS_HAZARDOUS_COMMODITY"));
bstrSELECTSQLQuery = _bstrSELECTSQLString.operator wchar_t*();

//END QUERY
pRecordset.CreateInstance(__uuidof(Recordset));

//Initialize the COM library
CoInitialize(NULL);

//Instantiate the COM object for the interface i.e. IDBM_ComDll
hr = CoCreateInstance(CLSID_GenericDBManager, NULL, CLSCTX_INPROC_SERVER,
IID_IGenericDBManager, (void **) &pGenericDBManager);
if (FAILED(hr))
{
MessageBox("\nIGenericDBManager Interface not instantiated\n", NULL, MB_OK);
return;
}
else
{
MessageBox("\nIGenericDBManager Interface instantiated\n", NULL, MB_OK);

VARIANT* pvntDB_Connect_Status = NULL;
BSTR* pbstrConnectErrString = NULL;

hr = pGenericDBManager->Connect((VARIANT*) &pvntDB_Connect_Status, pbstrConnectErrString);
if (SUCCEEDED(hr))
{

hr = pGenericDBManager->Fetch(bstrSELECTSQLQuery, &pRecordset, pbstrFetchErrString);
if (FAILED(hr))
{
MessageBox("\nIGenericDBManager::Fetch() failed\n", NULL, MB_OK);
return;
}
else
{
VARIANT* pConnection = NULL;
VARIANT* pTable = NULL;
_bstr_t _bstrTable(_T("GHDR1TS_HAZARDOUS_COMMODITY"));
_variant_t _vtTable(_bstrTable.operator const wchar_t *());

hr = pRecordset->get_ActiveConnection((VARIANT*) &pConnection);
_variant_t _vtConnection(*pConnection,true);
hr = pRecordset->Open( _vtTable.Detach(), _vtConnection.Detach(),adOpenKeyset,adLockOptimistic,adCmdText);

if(pRecordset != NULL)
{
int nRecordCount = pRecordset->RecordCount;
int nMaxRecords = pRecordset->MaxRecords;
int nFieldCount = pRecordset->Fields->Count;

MessageBox((LPCTSTR) nRecordCount, NULL, MB_OK );
MessageBox((LPCTSTR) nMaxRecords, NULL, MB_OK );

pRecordset->MoveFirst();
for (int i = 0; i< nRecordCount; nRecordCount++)
{
for(int j=0; j< nFieldCount; j++)
{
MessageBox((LPCTSTR)pRecordset->Fields->GetItem("IMO")->Value.bstrVal, NULL, MB_OK);
}

pRecordset->MoveNext();
}

pRecordset->Close();
}
else
{
MessageBox("NULL RECORDSET", NULL, MB_OK);
pRecordset->Close();
}
}
}
else
{
MessageBox("CONNECT FAILURE", NULL, MB_OK);
}

}

//Uninitialize the COM library
CoUninitialize();

}
/Smile | :) Smile | :)
GeneralRe: First-chance exception in GH_DBM_COMDLL_Stub_MFC_EXE.exe: 0xC0000005: Access Violation Pin
Mike Dimmick9-Dec-03 3:29
Mike Dimmick9-Dec-03 3:29 
GeneralHELP PLEASE! Pin
bhangie9-Dec-03 0:24
bhangie9-Dec-03 0:24 
GeneralRe: HELP PLEASE! Pin
David Crow9-Dec-03 2:59
David Crow9-Dec-03 2:59 
GeneralRe: HELP PLEASE! Pin
Alexander M.,9-Dec-03 4:51
Alexander M.,9-Dec-03 4:51 
Generalhook functions in another process Pin
RicoH8-Dec-03 23:06
RicoH8-Dec-03 23:06 
GeneralRe: hook functions in another process Pin
jmkhael8-Dec-03 23:23
jmkhael8-Dec-03 23:23 
GeneralRe: hook functions in another process Pin
RicoH8-Dec-03 23:32
RicoH8-Dec-03 23:32 
GeneralRe: hook functions in another process Pin
jmkhael8-Dec-03 23:44
jmkhael8-Dec-03 23:44 
GeneralRe: hook functions in another process Pin
RicoH8-Dec-03 23:50
RicoH8-Dec-03 23:50 
GeneralRe: hook functions in another process Pin
jmkhael9-Dec-03 0:16
jmkhael9-Dec-03 0:16 
GeneralRe: hook functions in another process Pin
RicoH9-Dec-03 0:19
RicoH9-Dec-03 0:19 
GeneralRe: hook functions in another process Pin
Alexander M.,9-Dec-03 4:58
Alexander M.,9-Dec-03 4:58 
Generalatoi problems Pin
styve8-Dec-03 22:43
styve8-Dec-03 22:43 
GeneralRe: atoi problems Pin
jmkhael8-Dec-03 22:49
jmkhael8-Dec-03 22:49 
GeneralRe: atoi problems Pin
Ian Darling8-Dec-03 23:31
Ian Darling8-Dec-03 23:31 
QuestionA Stupid doubt???? Pin
Ilamparithi8-Dec-03 22:42
Ilamparithi8-Dec-03 22:42 
AnswerRe: A Stupid doubt???? Pin
jmkhael8-Dec-03 22:51
jmkhael8-Dec-03 22:51 

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.