VOID InitializeCriticalSection(
  LPCRITICAL_SECTION lpCriticalSection   // address of critical 
                                         // section object
);// 怎么设置参数lpCriticalSection?LPCRITICAL_SECTION lpCriticalSection;lpCriticalSection->LockCount =?;
lpCriticalSection->LockSemaphore =  ?
lpCriticalSection->DebugInfo = ?
  ...InitializeCriticalSection(lpCriticalSection);
MSDN中 找不到lpCriticalSection的参数说明,请教怎么设置它们?

解决方案 »

  1.   

    如果不初始化有一个编译警告的,我想应该初始化它的,但是看了MSDN就是找不到它的结构说明,我是中文版(2CD)的.谢谢大家帮我看看...
      

  2.   

    LPCRITICAL_SECTION lpCriticalSection;... 这里怎么设置 lpCriticalSection?  // 肯定得初始化,否则下面就出地址无效的错误InitializeCriticalSection(lpCriticalSection);
      

  3.   

    typedef struct _RTL_CRITICAL_SECTION {
        LONG LockCount;
        LONG RecursionCount;
        HANDLE OwningThread;        // from the thread's ClientId->UniqueThread
        HANDLE LockSemaphore;
        DWORD SpinCount;
    } *lpCriticalSection;怎么设置? help me...
      

  4.   

    msdn上的例子
    Using Critical Section Objects
    The following example shows how a thread initializes, enters, and leaves a critical section. As with the mutex example (see Using Mutex Objects), this example uses structured exception-handling syntax to ensure that the thread calls the LeaveCriticalSection function to release its ownership of the critical section object. CRITICAL_SECTION CriticalSection; // Initialize the critical section.
    InitializeCriticalSection(&CriticalSection); // Request ownership of the critical section.
    __try 
    {
        EnterCriticalSection(&CriticalSection);     // Access the shared resource.
    }
    __finally 
    {
        // Release ownership of the critical section.
        LeaveCriticalSection(&CriticalSection);    // Release resources used by the critical section object.
        DeleteCriticalSection(&CriticalSection)
    }
      

  5.   

    给你代码,未运行测试,应该没有什么问题的.H
    class CMyList  
    {
    protected:
    CStringArray m_arr; //MFC类库的数组
    CRITICAL_SECTION m_cs; //关键区对象,注意,不是指针!!
    public:
    int Count();
    CString GetAt(int nIndex);
    void Add(const CString& s);
    CMyList();
    virtual ~CMyList();

    };CPP...............CMyList::CMyList()
    {
    //初始化关键区
    InitializeCriticalSection( &m_cs); 
    }CMyList::~CMyList()
    {
    //删除关键区
    DeleteCriticalSection(&m_cs);}
    void CMyList::Add(const CString &s)
    {
    //进入
    EnterCriticalSection(&m_cs); m_arr.Add (s);
    //离开
    LeaveCriticalSection(&m_cs);
    }//下边代码应该有长度监测之类的过程,忽略
    CString CMyList::GetAt(int nIndex)
    {
    //进入
    EnterCriticalSection(&m_cs); CString s=m_arr.GetAt (nIndex); //离开
    LeaveCriticalSection(&m_cs);
    return s;
    }int CMyList::Count()
    {
    //进入
    EnterCriticalSection(&m_cs);
    int nCnt=m_arr.GetSize ();
    //离开
    LeaveCriticalSection(&m_cs);
    return nCnt;
    }