slv
November 8th, 2004, 01:08 PM
hi. i am having a problem with a thread and i hope you can help me solve it. my problem is that the param that i pass to the function that performs the thread seem to have benn lost on the way. the thing is that when i try to print them they are NULL. The code for the class is:
Download.h
#pragma once
typedef struct ThreadInfo {
CString strFile;
CString strUrl;
}ThreadInfo;
class Download {
public:
Download(void);
~Download(void);
Download(const char* Url , const char* File);
protected:
ThreadInfo ti;
public:
UINT StartThread(void);
static UINT DownloadFile(LPVOID pParam);
};
And the Download.cpp is:
#include "StdAfx.h"
#include ".\download.h"
Download::Download(void) {
}
Download::~Download(void) {
}
Download::Download(const char* Url , const char* File) {
ti.strFile = Url;
ti.strUrl = File;
}
UINT Download::StartThread(void) {
AfxMessageBox(ti.strFile);
if ( AfxBeginThread(DownloadFile, this))
return 0;
else
return 1;
}
UINT Download::DownloadFile(LPVOID pParam) {
Download * file = reinterpret_cast<Download*> (pParam); AfxMessageBox("yes!");
AfxMessageBox(file->ti.strUrl);
return 1;
}
And to use it :
Download file("http://slv.com", "slv"); file.StartThread();
i looked all-over 4 an answer but i colud not find one. I've seen exaples, they look the same, they work, but mine doesn't.
Download.h
#pragma once
typedef struct ThreadInfo {
CString strFile;
CString strUrl;
}ThreadInfo;
class Download {
public:
Download(void);
~Download(void);
Download(const char* Url , const char* File);
protected:
ThreadInfo ti;
public:
UINT StartThread(void);
static UINT DownloadFile(LPVOID pParam);
};
And the Download.cpp is:
#include "StdAfx.h"
#include ".\download.h"
Download::Download(void) {
}
Download::~Download(void) {
}
Download::Download(const char* Url , const char* File) {
ti.strFile = Url;
ti.strUrl = File;
}
UINT Download::StartThread(void) {
AfxMessageBox(ti.strFile);
if ( AfxBeginThread(DownloadFile, this))
return 0;
else
return 1;
}
UINT Download::DownloadFile(LPVOID pParam) {
Download * file = reinterpret_cast<Download*> (pParam); AfxMessageBox("yes!");
AfxMessageBox(file->ti.strUrl);
return 1;
}
And to use it :
Download file("http://slv.com", "slv"); file.StartThread();
i looked all-over 4 an answer but i colud not find one. I've seen exaples, they look the same, they work, but mine doesn't.