MFC

CString appPath;
GetModuleFileName(NULL,appPath.GetBuffer(MAX_PATH),MAX_PATH);
appPath.ReleaseBuffer();
appPath = appPath.Left( appPath.ReverseFind('\\') + 1);
阅读全文 »

MFC

CString appPath;
GetModuleFileName(NULL,appPath.GetBuffer(MAX_PATH),MAX_PATH);
appPath.ReleaseBuffer();
appPath = appPath.Left( appPath.ReverseFind('\\') + 1);

win32

string getAppPath()
{
TCHAR path[MAX_PATH + 2] = { '\0' };
if (0 == GetModuleFileName(NULL, path, MAX_PATH))
{
//failed
AfxMessageBox(TEXT("Get File Path Failed"));
ASSERT(FALSE);
}
TCHAR* pf = _tcsrchr(path, '\\');//strrchr
if (NULL == pf)
{
//not found
AfxMessageBox(TEXT("Invalide File Path"));
ASSERT(FALSE);
}
*(pf + 1) = '\0';//path is xx\\

string str = &path[0];
return str;
}

Linux

int GetAppPath(std::string &sPath)
{
char buf[4097] = { 0 };
long size;
char *ptr;
size = pathconf(".", _PC_PATH_MAX);
if ((ptr = new char(size)) != NULL)
{
memset(ptr, 0, size);
sprintf(ptr, "/proc/%d/exe", getpid());
} else return -1;
readlink(ptr, buf, size);
delete[] ptr;
ptr = NULL;
sPath = buf;
int nPos = sPath.find_last_of("/");
sPath = sPath.substr(0, nPos + 1);
return 0;
}

添加环境变量

三个路径

F:\Anaconda3
F:\Anaconda3\Scripts
F:\Anaconda3\Library\bin

卸载

找到 Uninstall-Anaconda.exe 运行即可

设置代理

找到 .condarc 文件,添加下面代理
C:\Users\Tyler-Home.condarc

ssl_verify: true
channels:
- defaults
proxy_servers:
http: http://127.0.0.1:1081
https: http://127.0.0.1:1081
ALL_PROXY: socks5://127.0.0.1:1080

MySql Server
当前版本:mysql-installer-community-8.0.15.0.msi

MySql++ 库连接

MySql++

编译 MySql++,注意这里只能动态连接。静态链接官网说可能会有法律后果,具体没细看。

需要安装 MySQL Connector C 6.1,MySql++是基于这个接口库开发的。
C:\Program Files\MySQL\MySQL Connector C 6.1\include
路径下面有 vc 工程。打开设置 MySQL Connector C 6.1 的 include 和 lib,编译即可
mysql++-3.2.4\vc2008\

使用的时候,还需要 libmysql.dll

#include <mysql++.h>
#ifdef _DEBUG
#pragma comment(lib,"mysqlpp_d.lib")
#else
#pragma comment(lib,"mysqlpp.lib")
#endif

连接 MySql 8.0 是提示错误
DB connection failed: Authentication plugin ‘caching_sha2_password’ cannot be loaded: 找不到指定的模块。

使用 mysql 官方接口

使用下面的接口有问题,暂时不处理。

Connector/C++
当前版本:mysql-connector-c++-8.0.15-winx64.msi

Developer Guide

Connector/C++ 是连接MySQL的库,我们在C++中需要使用该库来连接数据库。

新建 MFC 工程

添加 Connector 的 include 和 lib 路径

动态链接

可以编译通过

Connector Type Import Library Dynamic Library
X DevAPI, X DevAPI for C LIB/vs14/mysqlcppconn8.lib LIB/mysqlcppconn8-1-vs14.dll
JDBC LIB/vs14/mysqlcppconn.lib LIB/mysqlcppconn-7-vs14.dll

静态链接

这个编译有问题,暂时没通

Connector Type Static Library
X DevAPI, X DevAPI for C LIB/vs14/mysqlcppconn8-static.lib
JDBC LIB/vs14/mysqlcppconn-static.lib

定义宏 STATIC_CONCPP

int LoadStringA(
HINSTANCE hInstance,
UINT uID,
LPSTR lpBuffer,
int cchBufferMax
);

int LoadStringA(
HINSTANCE hInstance,
UINT uID,
LPSTR lpBuffer,
int cchBufferMax
);

读取

3 是默认值
int extensions = GetPrivateProfileInt("sectionName","key",3,g_szIniFileName);

CString tmp,str;
#define MAX_LENGTH 216
GetPrivateProfileString("sectionName",key,NULL,str.GetBuffer(MAX_LENGTH),MAX_LENGTH,g_szIniFileName);
...处理代码
str.ReleaseBuffer(MAX_LENGTH);

写入

WritePrivateProfileString("sectionName","key","value",g_szIniFileName);

遍历

// 获取所有 section 内容
const int nBufferSize = 5120;
TCHAR lpszReturnBuffer[nBufferSize] = { '\0' };
DWORD dwRet = GetPrivateProfileSectionNames(lpszReturnBuffer, nBufferSize, path.c_str());
if (0==dwRet)
{
return -1;
}
m_listSections.clear();
list<wstring> listKVs;
TCHAR* pNextSection = NULL;
pNextSection = lpszReturnBuffer;
do
{
if (*pNextSection != 0x00)
{
m_listSections.push_back(pNextSection);
// 获取 section 下面所有key:value对
listKVs = getSectionData(pNextSection);
Json::Value jsonTmp;
for (auto&it:listKVs)
{
vector<wstring> wv = strHelper::strSplit(it, L"=");
if (wv.size() == 2)
{
jsonTmp[strHelper::w2s(wv[0]).c_str()] = strHelper::w2s(wv[1]);
}
else
{
g_logger->error("CIniTools::loadIni: kv parse failed. {}", strHelper::w2s(it));
}
}
m_json[strHelper::w2s(pNextSection)] = jsonTmp;
}
pNextSection = pNextSection + lstrlen(pNextSection) + 1;
} while (*pNextSection != 0x00);

读取

3 是默认值
int extensions = GetPrivateProfileInt("sectionName","key",3,g_szIniFileName);

CString tmp,str;
#define MAX_LENGTH 216
GetPrivateProfileString("sectionName",key,NULL,str.GetBuffer(MAX_LENGTH),MAX_LENGTH,g_szIniFileName);
...处理代码
str.ReleaseBuffer(MAX_LENGTH);

写入

WritePrivateProfileString("sectionName","key","value",g_szIniFileName);

遍历

// 获取所有 section 内容
const int nBufferSize = 5120;
TCHAR lpszReturnBuffer[nBufferSize] = { '\0' };
DWORD dwRet = GetPrivateProfileSectionNames(lpszReturnBuffer, nBufferSize, path.c_str());
if (0==dwRet)
{
return -1;
}
m_listSections.clear();
list<wstring> listKVs;
TCHAR* pNextSection = NULL;
pNextSection = lpszReturnBuffer;
do
{
if (*pNextSection != 0x00)
{
m_listSections.push_back(pNextSection);
// 获取 section 下面所有key:value对
listKVs = getSectionData(pNextSection);
Json::Value jsonTmp;
for (auto&it:listKVs)
{
vector<wstring> wv = strHelper::strSplit(it, L"=");
if (wv.size() == 2)
{
jsonTmp[strHelper::w2s(wv[0]).c_str()] = strHelper::w2s(wv[1]);
}
else
{
g_logger->error("CIniTools::loadIni: kv parse failed. {}", strHelper::w2s(it));
}
}
m_json[strHelper::w2s(pNextSection)] = jsonTmp;
}
pNextSection = pNextSection + lstrlen(pNextSection) + 1;
} while (*pNextSection != 0x00);

CreateProcess