我用VISUAL C++ 生成了一个,添加了一个Mothod:
    GetCount(long hdbc, long* RecordCount)使用到了ODBC的API,编译时没有问题,但是在连接时出了以下的错误:
ompiling resources...
Compiling...
CTest.cpp
Generating Code...
Compiling...
PersonInfo.cpp
Generating Code...
F:\技术研发\net\CTest\PersonInfo.cpp(30) : warning C4700: local variable 'szmn' used without having been initialized
Linking...
   Creating library Debug/CTest.lib and object Debug/CTest.exp
LINK : warning LNK4199: /DELAYLOAD:mtxex.dll ignored; no imports found from mtxex.dll
PersonInfo.obj : error LNK2001: unresolved external symbol _SQLFreeHandle@8
PersonInfo.obj : error LNK2001: unresolved external symbol _SQLFetch@4
PersonInfo.obj : error LNK2001: unresolved external symbol _SQLExecDirect@12
PersonInfo.obj : error LNK2001: unresolved external symbol _SQLAllocHandle@12
Debug/CTest.dll : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.CTest.dll - 5 error(s), 2 warning(s)下面是GetCount(long hdbc, long* RecordCount)的具体代码
STDMETHODIMP CPersonInfo::GetCount(long hdbc, long* RecordCount)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here
    char * strsql = "select count(ew05) from oa_data.sysdba.eswj where ew78 = '在职' " ;
SQLHSTMT hstmt;
    SQLRETURN retcode;
CString str;
SQLINTEGER szmn;
retcode = SQLAllocHandle(SQL_HANDLE_STMT, (SQLHDBC)hdbc, &hstmt); 
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) 
{
        //str = SQLCheckNullQuerySentence(sqlstr);
retcode = SQLExecDirect(hstmt, (SQLCHAR *)strsql, SQL_NTS); 
        if (retcode == SQL_SUCCESS || retcode == SQL_NO_DATA ||retcode == SQL_SUCCESS_WITH_INFO)

retcode = SQLFetch(hstmt);
            if (retcode == SQL_SUCCESS && szmn != SQL_NULL_DATA)
                *RecordCount = szmn;
else 
*RecordCount = 0;
        }
        retcode = SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
}
      return S_OK;
}
然后在cpp文件里面加了
#include "windows.h"
#include "sql.h"