Class problem

This is a discussion on Class problem within the C++ Programming forums, part of the General Programming Boards category; ListFiles is a member of my class... Code: _beginthread(ListFiles,0,NULL); ...and I'm getting this error: Code: main.h: In member function `void ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Class problem

    ListFiles is a member of my class...
    Code:
    _beginthread(ListFiles,0,NULL);
    ...and I'm getting this error:
    Code:
    main.h: In member function `void Conn::DeleteFileA(void*)':
    main.h:51: error: argument of type `void (Conn::)(void*)' does not match `void (*)(void*)'
    I am getting the same error with CreateThread.
    Last edited by maxorator; 10-04-2006 at 11:05 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You can't pass a non-static member function as the argument. The problem is that non-static member functions are passed the 'this' pointer implicitly and so the function type doesn't match what is expected.

    You can make a static member function with the correct parameters, then pass the this pointer to that function, eg:
    Code:
    class foo
    {
    public:
      foo() { CreateThread(0,0,(LPTHREAD_START_ROUTINE)ListFilesStart,this,0,0); }
      static DWORD ListFilesStart(foo* obj)
      {
        obj->ListFiles();
    return 0;
      }
      void ListFiles() { /*...*/ }
    };
    Last edited by JaWiB; 10-04-2006 at 11:18 AM.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    What kind of a sick error is this?
    Code:
    invalid conversion from `DWORD (*)(void*)' to `DWORD (*)(void*)'
    Last edited by maxorator; 10-04-2006 at 11:30 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Now this is giving me so much errors:
    Code:
    #include <windows.h>
    #include <string>
    
    class Conn{
    	public:
    		Conn();
    		~Conn();
    		char Server[256],User[256],Pass[256];
    		HWND *mainwnd, status;
    		bool Connect(),ListFiles(),DeleteFile();
    	protected:
    		static DWORD StartListFiles(Conn *obj){
    		static DWORD StartDelete(Conn *obj);
    		char FileName[256],LastOpen[256];
    		bool connected;
    		HWND login[6],loggedin[6];
    		std::string file_contents;
    		HINTERNET Handle;
    };
    
    Conn::Conn(){
    	connected=false;
    }
    
    Conn::~Conn(){
    }
    
    static DWORD Conn::StartListFiles(Conn *obj){
    	obj->ListFiles();
    	return 0;
    }
    
    static DWORD Conn::StartDelete(Conn *obj){
    	obj->DeleteFile();
    	return 0;
    }
    
    bool Conn::Connect(){
    	HINTERNET temp;
    	if((temp=InternetOpen(0,INTERNET_OPEN_TYPE_DIRECT,0,0,0))==0){
    		false;
    	}
    	else{
    		Handle=InternetConnect(temp,Server,INTERNET_DEFAULT_FTP_PORT,
    			User,Pass,INTERNET_SERVICE_FTP,INTERNET_FLAG_TRANSFER_ASCII,0);
    		if(Handle>NULL){
    			connected=true;
    		}
    		else{
    			return false;
    		}
    	}
    	return true;
    }
    
    bool Conn::DeleteFile(){
    	char temp[256];
    	if(MessageBox(*mainwnd,"Oled sa kindel, et tahad seda faili kustutada?","Kustuta fail",MB_YESNO)==IDYES){
    		SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Oota.. Kustutan faili");    
    		GetWindowText(loggedin[1],temp,256);
    		FtpDeleteFile(Handle,temp);
    		CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartListFiles,this,0,NULL);
    		if(strcmp(LastOpen,temp)==0){
    			SetWindowText(loggedin[0],"");
    			SetWindowText(loggedin[5],"");
    		}
    		SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Ootan k&#228;sklusi");
    	}
    	return 0;
    }
    
    bool Conn::ListFiles(){
    	WIN32_FIND_DATA FindFileData;
    	HINTERNET hFindFile=0;
    	int fan;
    	SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Oota...Tekitan failide nimekirja");
    	hFindFile = FtpFindFirstFile(Handle, "*.*", &FindFileData, INTERNET_FLAG_RELOAD, 0); 
    	if(hFindFile){
    		SendMessage(loggedin[1],CB_RESETCONTENT,0,0);
    		if((FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=FILE_ATTRIBUTE_DIRECTORY){
    			SendMessage(loggedin[1],CB_ADDSTRING,0,(LPARAM)FindFileData.cFileName);
    		}
    	}
    	while(InternetFindNextFile(hFindFile, &FindFileData)){
    		if((FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=FILE_ATTRIBUTE_DIRECTORY){
    			SendMessage(loggedin[1],CB_ADDSTRING,0,(LPARAM)FindFileData.cFileName);
    		}
    	}
    	SendMessage(loggedin[1],CB_SETCURSEL,0,0);
    	InternetCloseHandle(hFindFile);
    	if(FileName){
    		fan=(int)SendMessage(loggedin[1],CB_FINDSTRINGEXACT,(WPARAM)-1,(LPARAM)FileName);
    		if(fan!=CB_ERR){
    			SendMessage(loggedin[1],CB_SETCURSEL,(WPARAM)fan,0);
    		}
    	}
    	SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Ootan k&#228;sklusi");
    	return 0;
    }
    Edit:
    The errors said nothing about a missing bracket. They were all "couldnt overload" errors.
    Last edited by maxorator; 10-04-2006 at 12:31 PM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I really shouldn't try to post right before I have to go to class. The prototype for my function should have been:
    Code:
    static DWORD WINAPI ListFilesStart(foo* obj)
    which specifies the calling convention (WINAPI is defined as __stdcall, and __cdecl is usually the default calling convention). This specifies the order that arguments are pushed onto the stack if I recall correctly. No cast should be required in your call to CreateThread

    It looks like you have a few syntax errors in your code, including an extra bracket after the prototype for StartListFiles and static modifiers before the definitions of your member functions (only needed in the declaration, unless it is defined inside the class declaration)
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I had already fixed everything else except the WINAPI type.

    Got the thing working, I had one pointer which I hadn't initalized and that caused access violation.
    Last edited by maxorator; 10-05-2006 at 04:17 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mesh Class Design problem
    By sarah22 in forum Game Programming
    Replies: 2
    Last Post: 05-20-2009, 05:52 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  3. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 03:33 PM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21