winsock计划出错

时间:2011-01-16 07:12:04

标签: winapi winsock

  #include <winsock2.h>
      #include <windows.h>
#include<stdio.h>
#pragma comment(lib, "Ws2_32.lib")

     #include <iostream>
    using namespace std;



    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)

    {

      WSADATA wsaData;
WSAStartup(MAKEWORD(1,1), &wsaData);
SOCKET Sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(Sock == INVALID_SOCKET) 
    { 
    WSACleanup(); 
    return INVALID_SOCKET; 
    };

LPHOSTENT hostEntry;
in_addr iaHost;


SOCKADDR_IN Addr_in;
Addr_in.sin_family=AF_INET;
Addr_in.sin_addr.s_addr=inet_addr("10.0.2.6");
Addr_in.sin_port=htons(25);





if ( connect(Sock,(LPSOCKADDR)&Addr_in,sizeof(struct Addr_in)) == SOCKET_ERROR) 
        { 
WSACleanup(); 
return INVALID_SOCKET;
                };

struct Email { LPSTR sender , recipient , message , subject;  };
Email e = { "vin@jkdbk.com"  , "vinod@vrk.com" , "hi" , "joke"};

LPSTR lpszBuff = new char[500];
        //LPSTR vin=new char[500];
        recv(Sock,lpszBuff,500,0);
        cout << lpszBuff;
        sprintf(lpszBuff,"HELO Mail-Server\r\n");
        send(Sock,lpszBuff,strlen(lpszBuff),0);     
        recv(Sock,lpszBuff,100,0);
        cout << lpszBuff;
         //for (int i = 0;i>=0; i++)        {
        sprintf(lpszBuff,"MAIL FROM: %s\r\n",e.sender);
        send(Sock,lpszBuff,strlen(lpszBuff),0);
        recv(Sock,lpszBuff,100,0);
        sprintf(lpszBuff,"RCPT TO: %s\r\n",e.recipient);
        send(Sock,lpszBuff,strlen(lpszBuff),0);
        recv(Sock,lpszBuff,100,0);
        sprintf(lpszBuff,"DATA\r\nFROM: <%s>\r\nSUBJECT: %s\r\n%s\r\n.\r\n",e.sender,e.subject,e.message);
        send(Sock,lpszBuff,strlen(lpszBuff),0);
        recv(Sock,lpszBuff,100,0);
       //}
        sprintf(lpszBuff,"QUIT");
        send(Sock,lpszBuff,strlen(lpszBuff),0);
        //recv(s,lpszBuff,100,0);
        delete lpszBuff;

 WSACleanup();

         exit(0);



}

这是一个向邮件服务器发送邮件的程序,其地址是

它给了我错误

错误C2027:使用未定义类型'WinMain :: Addr_in'..

1 个答案:

答案 0 :(得分:3)

你有以下表达式:

sizeof(struct Addr_in)

要么

sizeof(Addr_in)

sizeof(SOCKADDR_IN)

现在,您的代码没有名为struct的{​​{1}}类型。

此外,请不要忘记在错误消息中包含行号,并指出源代码中指的是哪个实际行。你应该自己做这件事,但当我们试着回答你的问题时,这也有助于我们。