-
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.
-
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() { /*...*/ }
};
-
What kind of a sick error is this?
Code:
invalid conversion from `DWORD (*)(void*)' to `DWORD (*)(void*)'
-
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ä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äsklusi");
return 0;
}
Edit:
The errors said nothing about a missing bracket. They were all "couldnt overload" errors.
-
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)
-
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.