Export (0) Print
Expand All

GUIDGEN Sample: Generates Globally Unique Identifiers (GUIDs)

The GUIDGEN sample is a simple dialog-based MFC application that can help you as you code ActiveX applications. GUIDGEN can be used to generate globally unique identifiers, or GUIDs, that identify classes, objects, and interfaces.

Aside from being a dialog-box based application, GUIDGEN also shows how MFC applications can paste text data to the Clipboard. The CGuidGenDlg::OnOK function in the GUIDGDLG.CPP file shows how OpenClipboard and SetClipboardData can be called to accomplish this task. The application also demonstrates calling the CoCreateGuid API to request a new GUID from the operating system. Look for this code in CGuidGenDlg::OnNewguid, which is also in the GUIDGDLG.CPP file.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

If you have installed the Microsoft Visual C++ product, the GUIDGEN utility (GUIDGEN.EXE) is installed by default in \\Microsoft Visual Studio .NET 2003\Common7\Tools.

The radio buttons in the GUID Format group box determine the format of the GUID the program will generate.

  • The first format is designed to be used in invocations of MFC's IMPLEMENT_OLECREATE macro.

  • The second format generates a reference to the DEFINE_GUID macro.

The remaining formats are appropriate for statically allocated GUIDs and GUIDs included in registry entries or registry editor scripts.

Once you have selected the format for your GUID, you can copy it to the Clipboard with the Copy button. You can return to your editor and paste the GUID code into your application's source. When you need to generate a new GUID, click the New Guid button.

This sample demonstrates the following keywords:

AfxGetApp; AfxMessageBox; CDC::DrawIcon; CDC::GetSafeHdc; CDialog::DoModal; CDialog::EndDialog; CDialog::OnInitDialog; CDialog::OnOK; CMenu::AppendMenu; CRect::Height; CRect::Width; CString::Format; CString::GetLength; CString::IsEmpty; CString::LoadString; CWinApp::ExitInstance; CWinApp::InitInstance; CWinApp::SetRegistryKey; CWnd::CenterWindow; CWnd::DoDataExchange; CWnd::GetClientRect; CWnd::GetParent; CWnd::GetSystemMenu; CWnd::IsIconic; CWnd::OnPaint; CWnd::OnQueryDragIcon; CWnd::OnSysCommand; CWnd::OpenClipboard; CWnd::SendMessage; CWnd::SetDlgItemText; CWnd::UpdateData; CloseClipboard; CoInitialize; CoUninitialize; EmptyClipboard; GetForegroundWindow; GetProfileInt; GetSystemMetrics; GlobalAlloc; GlobalLock; GlobalUnlock; LoadIcon; SetClipboardData; memcpy

NoteNote

Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

Other Resources

Show:
© 2014 Microsoft