CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2007
    Posts
    15

    Thumbs down InitializeCriticalSectionAndSpinCount

    Hi, all,

    I'm new to Windows programming, though I've been doing C/C++ for about 8 years. I'm trying to use a CRITICAL_SECTION without any luck. I was trying to follow the example at

    http://msdn2.microsoft.com/en-us/library/ms683476.aspx

    I'm just trying to understand how the function calls work right now. I have :

    Code:
    #include <Windows.h>
    // ...
      res = InitializeCriticalSectionAndSpinCount(_cs, 0x80000400);
    // ...
      __try
      {
    	  EnterCriticalSection(_cs);
      }
      __except (EXCEPTION_POSSIBLE_DEADLOCK)
      {
    	  std::cout << "Deadlock?" << std::endl;
    	  exit(0);
      }
    However, I'm getting

    Code:
    error C3861: 'InitializeCriticalSectionAndSpinCount': identifier not found, even with argument-dependent lookup
    error C2065: 'EXCEPTION_POSSIBLE_DEADLOCK' : undeclared identifier
    What am I doing wrong? I'm using VisualStudio .NET 2003 on WinXP.

    Thanks!

    Don

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: InitializeCriticalSectionAndSpinCount

    include <process.h>.

    Also you need to pass in the address to the critical section in these functions (i.e. &_cs).

    Looks like the later msdn documentation recommends that you don't handle the EXCEPTION_POSSIBLE_DEADLOCK exception in your code.

  3. #3
    Join Date
    Oct 2007
    Posts
    15

    Re: InitializeCriticalSectionAndSpinCount

    Quote Originally Posted by Arjay
    include <process.h>.

    Also you need to pass in the address to the critical section in these functions (i.e. &_cs).

    Looks like the later msdn documentation recommends that you don't handle the EXCEPTION_POSSIBLE_DEADLOCK exception in your code.
    Thanks for the reply! _cs is a pointer in my example. With the deadlock exception, I was just trying to see if I had the syntax for that try/catch thing right.

    Cheers!

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: InitializeCriticalSectionAndSpinCount

    Okay, did you declare the cs object and a pointer (with the pointer pointing to the address of the cs) or did you just declare a pointer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured