Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么GetLastError()在调试和“正常”执行期间返回不同的代码?_C++_Windows_Visual Studio_Wininet - Fatal编程技术网

C++ 为什么GetLastError()在调试和“正常”执行期间返回不同的代码?

C++ 为什么GetLastError()在调试和“正常”执行期间返回不同的代码?,c++,windows,visual-studio,wininet,C++,Windows,Visual Studio,Wininet,当此代码在VisualStudio中以故意不正确的用户名运行时,GetLastError将返回12014 但是,当从命令行使用完全不正确的用户名运行相同的代码时,GetLastError返回2?GetErrorMessage返回的密码不正确 我不明白有什么区别 此外,在VisualStudio中将进程附加到该程序时,我从命令行运行该程序以进行调试。我收到了12014 无论何时涉及调试器,我都会得到12014。当我使用相同的参数正常运行可执行文件时,得到2 在调试器之外运行程序时,是否未找到Win

当此代码在VisualStudio中以故意不正确的用户名运行时,GetLastError将返回12014

但是,当从命令行使用完全不正确的用户名运行相同的代码时,GetLastError返回2?GetErrorMessage返回的密码不正确

我不明白有什么区别

此外,在VisualStudio中将进程附加到该程序时,我从命令行运行该程序以进行调试。我收到了12014

无论何时涉及调试器,我都会得到12014。当我使用相同的参数正常运行可执行文件时,得到2

在调试器之外运行程序时,是否未找到WinInet错误代码?我需要以不同的方式编译程序吗


感谢您的帮助。谢谢。

在这方面我的记忆有点模糊,但是如果使用CInternetException对象的m_dwError字段而不是调用GetLastError,会发生什么

我猜是有什么原因导致错误代码在实际错误发生和调用GetLastError之间重置。我不知道为什么在调试器外部运行而不是在调试器内部运行时会发生这种情况。但是,MFC会在抛出的对象中缓存导致异常的错误代码,因此无论抛出异常后发生了什么API调用,您都应该能够使用缓存的值


GetErrorMessage返回正确的错误字符串,因为它使用此m_dwError字段,而不是调用GetLastError。

我的内存在这方面有点模糊,但是如果使用CInternetException对象的m_dwError字段而不是调用GetLastError,会发生什么

我猜是有什么原因导致错误代码在实际错误发生和调用GetLastError之间重置。我不知道为什么在调试器外部运行而不是在调试器内部运行时会发生这种情况。但是,MFC会在抛出的对象中缓存导致异常的错误代码,因此无论抛出异常后发生了什么API调用,您都应该能够使用缓存的值

GetErrorMessage返回正确的错误字符串,因为它使用此m_dwError字段,而不是调用GetLastError。

m_dwError将起作用。谢谢。m_dwError将起作用。谢谢
try
{      

    pConnect = sess->GetFtpConnection(ftpArgs.host, ftpArgs.userName, ftpArgs.password, port, FALSE );
}
catch (CInternetException* pEx) 
{
    loginErrCode = GetLastError();
    printf("loginErrCode: %d\n", loginErrCode);

    if(loginErrCode == 12013)
    {
        printf("Incorrect user name!\n");
        exit(0);
    }
    else if(loginErrCode == 12014)
    {
        printf("Incorrect password!\n");
        exit(0);
    }
    else if(loginErrCode == 12007)
    {
        printf("Incorrect server name!\n");
        exit(0);
    }
    else //display all other errors
    {   
        TCHAR sz[1024];
        pEx->GetErrorMessage(sz, 1024);
        printf("ERROR!  %s\n, sz);
        pEx->Delete();
        exit(0);
    }