I built a library (with statically linked MFC), which has several functions working with database. There is a CDatabase pointer passed to those functions. Inside, it is opened using OpenEx function. With my application (Dialog based) it works fine.
Sample code within the library:
extern "C" __declspec(dllexport) void Test(CDatabase* pDb, CString& str)
{
BOOL bOpen=FALSE;
TRY
{
bOpen=pDb->OpenEx(_T("some dsn"), CDatabase::noOdbcDialog);
CRecordset rs;
rs.m_pDatabase=pDb;
rs.Open(AFX_DB_USE_DEFAULT_TYPE, _T("some select"));
rs.GetFieldValue((short)0, str);
rs.Close();
pDb->Close();
}
CATCH(CDBException, pEx)
{
str.Format(_T("OpenEx: %d; "), bOpen);
str+=pEx->m_strError;
}
END_CATCH
}
Pointer to CDatabase is passed because in original code I keep connection open for other operations.
When I tried to use those functions with console application (supporting MFC) OpenEx opens database in debug mode correctly. However in release mode returns codes 2025462466 or 2023703620 and throws no exception.
Sample code from console app:
extern "C" __declspec(dllimport) void Test(CDatabase* pDb, CString& str); //within .h file
...
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
if(!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
return 1;
}
CString str;
CDatabase db;
Test(&db, str);
_tprintf(_T("Info: ")+str);
return 0;
}
As I allowed debug info generating and debugged a library, Stepping into the CDatabase::OpenEx() worked as it should have in debug mode, but in release mode it was sent to an empty method:
CMFCTasksPaneToolBarCmdUI::SetRadio(BOOL /*bOn*/ = TRUE)
A piece of stack:
mfc90u.dll!CMFCTasksPaneToolBarCmdUI::SetCheck(int __formal=8) Line 3828 C++ ordbstat.dll!Test(CDatabase * pDb=0x00404460, ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL::ChTraitsCRT<wchar_t> > > & str="Init: 0") Line 349 C++ ServiceTest.exe!004010bb() [Frames below may be incorrect and/or missing, no symbols loaded for ServiceTest.exe] msvcr90.dll!_initterm(void (void)* * pfbegin=0x00000001, void (void)* * pfend=0x00b2c130) Line 903 C ServiceTest.exe!00401a5d() kernel32.dll!7c817077()
I’m using Visual Studio 2008.
Any suggestions will be appreciated.
Thanks.

New Topic/Question
Reply




MultiQuote







|