void GetFtpFile(LPCTSTR pszServerName, LPCTSTR pszRemoteFile, LPCTSTR pszLocalFile)
{
CInternetSession session(_T("My FTP Session"));
CFtpConnection* pConn = NULL;
pConn = session.GetFtpConnection(pszServerName);
//get the file
if (!pConn->GetFile(pszRemoteFile, pszLocalFile))
{
//display an error
}
delete pConn;
session.Close();
}
如何从 GetFile() 获取具体的错误信息?
谢谢。
最佳答案
根据MSDN :
Return Value
Nonzero if successful;
block 引用>otherwise 0. If the call fails, the Win32 function GetLastError may be called to determine the cause of the error.
GetLastError()返回错误代码,但您可以调用 FormatMessage()从错误代码中获取人类可读的字符串。这是一个可以为您完成此操作的实用函数:
std::string formatwinerr(unsigned long errCode) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM , 0, errCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); std::string ret((const char*)lpMsgBuf); LocalFree(lpMsgBuf); return ret; }
关于c++ - 如何从 GetFile() 获取具体的错误信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2158438/