静态的线程为什么不能访问类的成员变量??????(有代码)

coldplay968 2006-10-28 06:40:05
如题
void CMD5_Dlg2Dlg::OnButton1()
{

CString m_strFilePath;
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT, "All Files(*.*)|*.*||", this);
if(dlg.DoModal() == IDOK)
{
m_strFilePath = dlg.GetPathName(); //保存发送文件的路径
}
MD5 md5;
CString outHash ;
md5.CreateToThread(m_strFilePath);
md5.GetThreadHashFile();
GetDlgItem(IDC_EDIT1)->SetWindowText(outHash);
}


void MD5::CreateToThread(CString strFilePath)
{
DWORD id;
m_FilePath=strFilePath;
Path=strFilePath;
AfxMessageBox(Path);
HANDLE h = CreateThread(NULL, 0, ThreadHashFile, this, 0, &id);
CloseHandle(h);
}

DWORD WINAPI MD5::ThreadHashFile(LPVOID lpParam)
{
AfxMessageBox(" ThreadHashFile ");
CString tempHash = "";
MD5 * pMD5 = (MD5 *)lpParam;

// MD5 object to work with
MD5_CTX m_md5;
CString outHash;

AfxMessageBox(pMD5->Path); // 这里的Path值和CreateToThread()函数不同
if ( pMD5->Path.IsEmpty() )// 程序运行到这里就报错
return 0;

}
...全文
185 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
coldplay968 2006-10-31
  • 打赏
  • 举报
回复
是这个原因: md5在此是个局部变量,
结贴
wenbo_ying 2006-10-28
  • 打赏
  • 举报
回复
线程的同步没做好,反正要等计算完后再显示到界面上,就不要新建一个线程了
DentistryDoctor 2006-10-28
  • 打赏
  • 举报
回复
MD5 md5;//md5在此是个局部变量,到线程真正执行起来时,它的生命周期已经结束了
CString outHash ;
md5.CreateToThread(m_strFilePath);
md5.GetThreadHashFile();
coldplay968 2006-10-28
  • 打赏
  • 举报
回复
我在创建线成的时候传递了 this 指针啊,为什么还是不对呢??

15,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧