Article ID: 125794
Article Last Modified on 11/21/2006
/* 16-bit Compile options needed: /GD
* 16-bit Link options needed: /LIB:"odbc"
*/
#ifndef _WINDLL // Make this work with WIN32 and WIN16
#define _WINDLL
#endif
#ifndef _USRDLL
#define _USRDLL
#endif
#include <afxwin.h>
#include <afxext.h>
#include <afxdb.h>
class MyDLL : public CWinApp
{
public:
BOOL InitInstance();
};
#ifdef WIN32 // Make this work with WIN32 and WIN16
extern "C" __declspec(dllexport) int
#else
extern "C" int _export
#endif
FAR PASCAL OpenDatabase(HWND hWndParent /* Needs a parent window */)
{
TRY
{
// Before calling MyDb.Open setup a parent window
AfxGetApp()->m_pMainWnd = new CWnd;
AfxGetMainWnd()->Attach(hWndParent);
CDatabase MyDb;
// Present list of ODBC sources
MyDb.Open(NULL,FALSE,FALSE,"ODBC;");
MyDb.Close();
// Clean Up
AfxGetMainWnd()->Detach();
delete AfxGetMainWnd();
AfxGetApp()->m_pMainWnd = NULL;
}
CATCH_ALL(e)
{
if ( AfxGetMainWnd()->GetSafeHwnd() != NULL )
{
// Clean Up
AfxGetMainWnd()->Detach();
delete AfxGetMainWnd();
AfxGetApp()->m_pMainWnd = NULL;
}
// Exception caused a failure
return FALSE;
}
END_CATCH_ALL
return TRUE;
}
BOOL MyDLL::InitInstance()
{
return TRUE;
}
MyDLL theDLL;
Additional query words: 1.00 1.50 2.00 2.10 2.50 2.51 2.52 3.00 3.10
Keywords: kbprb kbcode KB125794