// lyfztestodbc.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "lyfztestodbc.h" #include #ifdef _DEBUG #define new DEBUG_NEW #endif // 唯一的应用程序对象 CWinApp theApp; using namespace std; volatile LONG nThreadCount = 0; unsigned __stdcall ThreadWork( LPVOID lpInput ) //DWORD WINAPI ThreadWork( LPVOID lpInput ) { IODBCPoolInterface *pInstance = (IODBCPoolInterface *)lpInput; DWORD dwThreadId = GetCurrentThreadId(); CArray Ary; //pInstance->GetOrderInfo( &Ary , 5000); pInstance->GetEnterprisInfo(_T("多多福"), Ary); //Sleep(10); InterlockedIncrement(&nThreadCount); // printf("Thread Finish Count = %d\n", nThreadCount); printf("log[%d]:\t %d\n",dwThreadId,nThreadCount); // for ( int i = 0; i < Ary.GetSize(); i++ ) { CStringArray &strAry = Ary.ElementAt(i); for ( int n = 0; n < strAry.GetSize(); n++ ) { printf("log[%d]: %s\n",dwThreadId, strAry.ElementAt(n)); } } return 0; } int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // 初始化 MFC 并在失败时显示错误 if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: 更改错误代码以符合您的需要 _tprintf(_T("错误: MFC 初始化失败\n")); nRetCode = 1; } else { // TODO: 在此处为应用程序的行为编写代码。 ////////////////////////////////////////////////////////////////////////// // 测试用例; IODBCPoolInterface *pInstance = lyfzCreatePoolInstance(); if ( pInstance == NULL ) { printf("log:打开数据库连接池失败\n"); return -1; } /* DWORD dwCount = pInstance->InitializePool(_T("IT-SERVER\\SQLEXPRESS"), 0, _T("sa"), _T("ly1234"), _T("219"), 5, 20); */ DWORD dwCount = pInstance->InitializePool(_T("192.168.1.223"), 1011, _T("sa"), _T("ly1234"), _T("dbmsg"), 5, 20); if ( dwCount == 0 ) { printf("log:创建连接对象0个,退出\n"); return -1; } int ncount = 0; for ( int i = 0; i < 100; i++) { Sleep(50);// 注释这个,会内存泄漏; unsigned int nThreadID = 0; //HANDLE hThread = CreateThread(NULL, 0, ThreadWork, pInstance, 0, NULL); HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, ThreadWork, pInstance, 0, &nThreadID); if (hThread) { ncount++; CString strNum = _T(""); strNum.Format(_T("----创建线程成功: %d--------\n"), ncount); OutputDebugString(strNum); CloseHandle(hThread); //_endthreadex(hThread); } } system("pause"); printf("\t\t %d \n\n\n",nThreadCount); pInstance->Release(); // 必须保证线程全部执行完成后才可以结束! system("pause"); } return nRetCode; }