I'm facing a weird problem. I have the below struct and the method that uses the struct.
struct AsyncData {
string documentNo;
string command;
string filePath;
};
UINT AsyncDownloader(LPVOID pData) {
AsyncData* ad = static_cast<AsyncData*>(pData);
string cmd = ad->command;
string path = ad->filePath;
HRESULT hr = URLDownloadToFile(NULL, cmd, path, 0, NULL );
if(SUCCEEDED(hr))
{
delete ad;
return 0;
}
else
{
string val = ad->documentNo;
return 1;
}
}
The call comes from another method:
callerMethod()
{
AsyncData* ad;
ad = new (AsyncData);
ad->filePath = filePath;
ad->command = command;
ad->documentNo = m_Target->SelectedDocNoList.GetString(i);
AfxBeginThread(AsyncDownloader, (LPVOID)ad);
}
The problem is:
When the AsyncDownloader
method gets called, the address of the struct sent and received is the same. But accessing the members, gives NULL
values.
Any insights on what I'm doing wrong?