书上有这么一段话:   一些 windows 函数调用成功可能是缘于不同的原因。例如,创建一个具名事件内核对象时,以下两种情况均会成功:对象实际完成创建,或者存在另一个同名的事件内核对象。应用程序也许需要知道成功的原因。为返回这种信息,Microsoft 选择采用“上一个错误代码”(last error code)机制。所以,特定函数调用成功时,可以调用 GetLastError 来确定额外的信息。对于具有这种行为的函数,Platform SDK 文档会清楚指明能以这种方式调用 GetLastError 。文档中提供了 CreateEvent 函数的一个例子;如果已经存在具名事件,就返回 ERROR_ALREADY_EXISTS。

解决方案 »

  1.   

    CreateEvent的时候lpName不是0得到的
      

  2.   

    HANDLE WINAPI CreateEvent(
      __in_opt  LPSECURITY_ATTRIBUTES lpEventAttributes,
      __in      BOOL bManualReset,
      __in      BOOL bInitialState,
      __in_opt  LPCTSTR lpName
    );lpName 
    The name of the event object. The name is limited to MAX_PATH characters. Name comparison is case sensitive. If lpName matches the name of an existing named event object, this function requests the EVENT_ALL_ACCESS access right. In this case, the bManualReset and bInitialState parameters are ignored because they have already been set by the creating process. If the lpEventAttributes parameter is not NULL, it determines whether the handle can be inherited, but its security-descriptor member is ignored. If lpName is NULL, the event object is created without a name.If lpName matches the name of an existing semaphore, mutex, waitable timer, job, or file-mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same name space.The name can have a "Global\" or "Local\" prefix to explicitly create the object in the global or session name space. The remainder of the name can contain any character except the backslash character (\). For more information, see Kernel Object Namespaces. Fast user switching is implemented using Terminal Services sessions. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users.Windows 2000:   If Terminal Services is not running, the "Global\" and "Local\" prefixes are ignored. The remainder of the name can contain any character except the backslash character. 
    The object can be created in a private namespace. For more information, see Object Namespaces.
      

  3.   

    HANDLE CreateEvent(
      LPSECURITY_ATTRIBUTES lpEventAttributes, // SD
      BOOL bManualReset,                       // reset type
      BOOL bInitialState,                      // initial state
      LPCTSTR lpName                           // object name
    );新建一个事件,名字可以有两种方式,一种是给名称,一种是不给名称
    CreateEvent(NULL,FALSE,FALSE,"Object"); // 具名对象
    CreateEvent(NULL,FALSE,FALSE,NULL);