mylib.cpp

来自「一种基于启发式算法(互信息熵)的粗糙集约简源代码」· C++ 代码 · 共 86 行

CPP
86
字号
// Mylib.cpp: implementation of the CMylib class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "Mylib.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////////
#include <odbcinst.h>  
//Config:Project/Settings.../Link /Object/library Modules  add "odbccp32.lib"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMylib::CMylib()
{

}

CMylib::~CMylib()
{

}
BOOL CMylib::ConfigAccess(CString strDBSource, CString strDBFilePath)
{
	WIN32_FIND_DATA cFindData;
	if(INVALID_HANDLE_VALUE==FindFirstFile((CString)strDBFilePath,&cFindData))
	{
		AfxMessageBox("Cannot find the file: "+strDBFilePath);
		return FALSE;
	}
	
	CString mdbpath=(CString)strDBFilePath;
	char* szDesc;
	int mlen;
	szDesc=new char[256];
	sprintf(szDesc,"DSN=%s: DESCRIPTION=: FIL=MicrosoftAccess: DEFAULTDIR=: DBQ=%s\0",
		strDBSource,mdbpath);
	mlen = strlen(szDesc);
	int numPath=0;
	for (int i=0; i<mlen; i++)
	{
		if(numPath==4)
			continue;
		if (szDesc[i] == ':')
		{
			szDesc[i] = '\0';
			numPath++;
		}
	}	
	if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
	{
		AfxMessageBox(" Error:when ConfigAccess()");
		return FALSE;
	}
	return TRUE;
	
}

CString CMylib::GetHomeDirectory()
{
	TCHAR sFilename[_MAX_PATH];
	TCHAR sDrive[_MAX_DRIVE];
	TCHAR sDir[_MAX_DIR];
	TCHAR sFname[_MAX_FNAME];		//not include extend name.
	TCHAR sExt[_MAX_EXT];			//extend name,have "." before head.
	GetModuleFileName(AfxGetInstanceHandle(), sFilename, _MAX_PATH);
	_tsplitpath(sFilename, sDrive, sDir, sFname, sExt);
	
	CString homeDir(CString(sDrive) + CString(sDir));
	int nLen=homeDir.GetLength();
	if (homeDir.GetAt(nLen-1) != _T('\\'))
		homeDir+=_T("\\");	  
	return homeDir;	
	//SetCurrentDirectory(homeDir);
}



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?