0
bool CInetWrapper::OpenFtpConnection (LPCTSTR lpszServerName)
{
    // internetconnect(inet_open,'ftp.site.ru',port,'login','pass',INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0);



    if (OpenInternet() && m_hConnection == NULL)
        // (HINTERNET,LPCSTR,INTERNET_PORT,LPCSTR,LPCSTR,DWORD,DWORD,DWORD);
        typedef HINTERNET (__stdcall* InternetConnect_)(HINTERNET,LPCSTR,INTERNET_PORT,LPCSTR,LPCSTR,DWORD,DWORD,DWORD);
        InternetConnect_ ic = (InternetConnect_)helper.GetProcAddressEx("wininet.dll", "InternetConnectA");
        m_hConnection = ic(
        m_hInternet,
        lpszServerName? lpszServerName:
            m_lpszServerName? m_lpszServerName: "localhost",
        INTERNET_DEFAULT_FTP_PORT,
        m_login,
        m_password,
        INTERNET_SERVICE_FTP,
        0,
        0);


    return CheckError(m_hConnection != NULL);
}

和编译器说: 1>----- 构建开始:项目:klstart,配置:调试 Win32 ------ 1> HTTPReader.cpp 1>c:\u\admin\visual studio 2010\projects\klstart \klstart\httpreader.cpp(100): 错误 C2065: 'InternetConnect_': 未声明的标识符 1>c:\u\admin\visual studio 2010\projects\klstart\klstart\httpreader.cpp(100): 错误 C2146: 语法错误: 失踪 ';' 在标识符“助手”之前我写错了什么?

4

2 回答 2

3

您忘记将您的真正分支包装if成复合语句。

基本上,问题与这段代码相同

if (some_condition)
  typedef int MyType;
  MyType i; // ERROR: `MyType` is undeclared identifier
  ...

在上面的简单示例中,虚构的“作者”想要这样做

if (something)
{
  typedef int MyType;
  MyType i; 
  ...
}

但他忘了把那些放在{}那里,结果得到了完全不同的东西。您在代码中犯了同样的错误。

由于您没有在if(使用{})之后创建复合语句,因此包含在其真正分支中的唯一部分if是您的typedef,仅此而已。那个单独的分支typedef是一个单独的本地范围,在此之后立即结束if。这意味着在您的iftypenameInternetConnect_不再为人所知之后。

要么把你的放在你的typedef之前if,要么把真正的分支包成一对{}

于 2012-10-27T19:09:56.547 回答
-1

尝试使用#include <cstdlib>

或者尝试使用结构,会更简单,更容易理解,出错的机会更少。

于 2012-10-27T19:06:57.330 回答