to zzh():
模块之间最好不要互相操作,可以通过互斥量或临界区来解决这个问题 ???
能否给出一点简单示例代码?

解决方案 »

  1.   

    你可以先建立个共有的结构,以后传递指针就行了
    如:
    //共有结构
    struct ThreadCommArea
    {  CString sURL;
       BOOL bSuccessful;
    };
    ThreadCommArea CommArea;
    .................
    //创建进程
    AfxBeginThread(Thread Proc,&CommArea);
    //在线程中访问结构
    UNIT ThreadProc(LPVOID pParam)
    {
    ThreadCommArea *pComm=(ThreadCommArea *)pParam;
    ...logic for thread...
    return 0;}
    //在线程中可以通过共有结构通信,不过要用临界区
    CCriticalSetion cs;
    ....cs.Lock();//锁定
    pComm->sURL=....;//修改共有变量
    ......
    cs.Unlock();