July 18, 2008

How to generate UUID (GUID) in C++?

Sample Code:

#include <Rpc.h>
#pragma comment(lib, "Rpcrt4.lib")

UUID uuid;
::ZeroMemory(&uuid, sizeof(UUID));

// Create uuid or load from a string by UuidFromString() function
::UuidCreate(&uuid);

// If you want to convert uuid to string, use UuidToString() function
WCHAR* wszUuid = NULL;
::UuidToStringW(&uuid, &wszUuid);
if(wszUuid != NULL)
{
  ::RpcStringFree(&wszUuid);
  wszUuid = NULL;
}


Reference in MSDN:

July 17, 2008

How to use named system events (global events) in C#?

There are three classes relating to windows events, EventWaitHandle, AutoResetEvent, and ManualResetEvent.

EventWaitHandle
The EventWaitHandle class can represent either automatic or manual reset events and either local events or named system events.

AutoResetEvent
The AutoResetEvent class derives from EventWaitHandle and represents a local event that resets automatically.

ManualResetEvent
The ManualResetEvent class derives from EventWaitHandle and represents a local event that must be reset manually.

Tips:
According to above description, you should use EventWaitHanlde class to represent named system events, of course it can be either automatic or manual reset events.

MSDN reference:
http://msdn.microsoft.com/en-us/library/ksb7zs2x.aspx