1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help in OOP

Discussion in 'C++' started by medopunsher, Sep 2, 2010.

  1. medopunsher

    medopunsher New Member

    Joined:
    Sep 2, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello Everyone ,
    I'am new to OOP and QT and i'm trying to write a simple chat program (client , server) with winsockets.
    I Have an error which i don't seem to understand :

    this is my code so far :

    Code:
    #include "pmessenger.h"
    #include "ui_pmessenger.h"
    SOCKET s;
    PMessenger::PMessenger(QWidget *parent) : QMainWindow(parent), ui(new Ui::PMessenger)
    {
        ui->setupUi(this);
        WSADATA wsadata;
        if(WSAStartup(MAKEWORD(2,2),&wsadata)!=0)
        {
             QMessageBox::critical(this,"Error","Winsock Startup Failed",0,0);
             this->close();
        }
        s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
        if(s==INVALID_SOCKET)
        {
              QMessageBox::critical(this,"Error","Socket Creation Faild",0,0);
              WSACleanup();
              this->close();
        }
        SOCKADDR_IN server;
        server.sin_family = AF_INET;
        server.sin_port = htons(7676);
        server.sin_addr.s_addr = inet_addr("my ip is here :D");
        if(::connect(s,(sockaddr*)&server,sizeof(server))!=0)
        {
              QMessageBox::critical(this,"Error","Can't Connect",0,0);
              WSACleanup();
              this->close();
        }
        CreateThread(NULL,0,ServerMsgThread,(LPVOID)s,0,0); // the problem is in this line :(
    }
    
    PMessenger::~PMessenger()
    {
        delete ui;
    }
    
    void PMessenger::on_pushButton_clicked()
    {
        QString msg = ui->plainTextEdit_2->toPlainText();
        send(s,(const char *)msg.data(),4096,0);
    }
    
    void PMessenger::AddMessege(char msg[4096])
    {
        ui->plainTextEdit->appendPlainText(msg);
    }
    
    DWORD PMessenger::ServerMsgThread(LPVOID pParam)
    {
          SOCKET Cs = (SOCKET) pParam;
          char data[4096];
          while(1)
          {
               if(recv(Cs,data,1024,0)>0)
                   AddMessege(data);
          }
          return 0;
    }
    I Get the following error :

    ..\PMessenger\pmessenger.cpp:32: error: argument of type 'DWORD (PMessenger:: )(void*)' does not match 'DWORD (*)(void*)'

    Any help would be greatly appreciated (i really don't want to move to wxWidgets because of that error)

    Thanks
     

Share This Page