#include <afxcoll.h> //Needed for CStringList MFC class.
#include "odbcinst.h"
#include "sql.h"
#include "sqlext.h"
// NOTE: in 16-bit Visual C++ link with odbcinst.lib
// in 32-bit Visual C++ 2.x link with odbccp32.lib
// in 32-bit Visual C++ 4.x no need to change link options
#define MAX_DSN_LENGTH 30
#define MAX_DSN_DESC_LENGTH 300
BOOL GetODBCDataSourceNames(CStringList * pList)
{
HENV hEnv;
char szDSN[MAX_DSN_LENGTH];
SWORD cbDSN;
UCHAR szDescription[MAX_DSN_DESC_LENGTH];
SWORD cbDescription;
RETCODE retcode;
ASSERT(pList->IsEmpty());
if (SQLAllocEnv(&hEnv)!=SQL_SUCCESS)
return FALSE;
while (retcode=SQLDataSources(hEnv, SQL_FETCH_NEXT,
(UCHAR FAR *) &szDSN, MAX_DSN_LENGTH, &cbDSN,
(UCHAR FAR *) &szDescription,MAX_DSN_DESC_LENGTH,
&cbDescription) != SQL_NO_DATA_FOUND
&&retcode!=SQL_ERROR)
{
pList->AddTail(szDSN);
}
SQLFreeEnv(hEnv);
if (retcode==SQL_ERROR)
return FALSE;
return TRUE;
}