Professional Documents
Culture Documents
There are several broad categories of Windows applications that you can create with C++. Each has its own
programming model and set of Windows-specific libraries, but the C++ standard library and third-party C++
libraries can be used in any of them.
This section discusses how to use Visual Studio and the MFC/ATL wrapper libraries to create Windows
programs. For documentation on the Windows platform itself, see Windows documentation.
COM Components
The Component Object Model (COM) is a specification that enables programs written in different languages to
communicate with one another. Many Windows components are implemented as COM objects and follow
standard COM rules for object creation, interface discovery, and object destruction. Using COM objects from
C++ desktop applications is relatively straightforward, but writing your own COM object is more advanced. The
Active Template Library (ATL) provides macros and helper functions that simplify COM development. For more
information, see ATL COM desktop components.
Desktop Bridge
In Windows 10 and later, you can package your existing desktop application or COM object as a UWP app. It can
use UWP features such as touch, or call APIs from the modern Windows API set. You can also add a UWP app to
a desktop solution in Visual Studio, package them together in a single package, and use Windows APIs to
communicate between them.
Visual Studio 2017 version 15.4 and later lets you create a Windows Application Package Project to greatly
simplify the work of packaging your existing desktop application. A few restrictions apply to the registry calls or
APIs your desktop application can use. However, in many cases you can create alternate code paths to achieve
similar functionality while running in an app package. For more information, see Desktop Bridge.
Games
DirectX games can run on the PC or Xbox. For more information, see DirectX Graphics and Gaming.
Windows services
A Windows service is a program that can run in the background with little or no user interaction. These
programs are called daemons on UNIX systems. For more information, see Services.
Development Tools
Visual Studio includes a powerful debugger for native code, static analysis tools, graphics debugging tools, a
full-featured code editor, support for unit tests, and many other tools and utilities. For more information, see Get
started developing with Visual Studio, and Overview of C++ development in Visual Studio.
In this section
-- --
Walkthrough: Creating Windows Desktop Applications (C++) Create a native Windows desktop application.
Windows Desktop Wizard Use the wizard to create new Windows projects.
Active Template Library (ATL) Use the ATL library to create COM components in C++.
Microsoft Foundation Classes (MFC) Use MFC to create large or small Windows applications with
dialogs and controls
ATL and MFC Shared Classes Use classes such as CString that are shared in ATL and MFC.
-- --
Working with Resource Files How to add images, icons, string tables, and other resources
to a desktop application.
Resources for Creating a Game Using DirectX (C++) Links to content for creating games in C++.
How to: Use the Windows SDK in a Windows Desktop Contains steps for setting up your project to build using the
Application Windows SDK.
Related Articles
T IT L E DESC RIP T IO N
C++ in Visual Studio Parent topic for Visual C++ developer content.
.NET Development with C++/CLI Create wrappers for native C++ libraries that enable it to
communication with .NET applications and components.
Component Extensions for .NET and UWP Reference for syntax elements shared by C++/CX and
C++/CLI.
Universal Windows Apps (C++) Write UWP applications using C++/CX or Windows Runtime
Template Library (WRL).
C++ Attributes for COM and .NET Non-standard attributes for Windows-only programming
using .NET or COM.
Desktop Applications (Visual C++)
7/27/2022 • 4 minutes to read • Edit Online
A desktop application in C++ is a native application that can access the full set of Windows APIs and either runs
in a window or in the system console. Desktop applications in C++ can run on Windows XP through Windows
11 (although Windows XP is no longer officially supported and there are many Windows APIs that have been
introduced since then).
A desktop application is distinct from a Universal Windows Platform (UWP) app, which can run on PCs running
Windows 11, Windows 10, XBox, Windows Phone, Surface Hub, and other devices. For more information about
desktop vs. UWP applications, see Choose your technology.
Desktop Bridge
In Windows 10 and later, you can package your existing desktop application or COM object as a UWP app. Apps
can add UWP features such as touch, or call APIs from the modern Windows API set. You can also add a UWP
app to a desktop solution in Visual Studio, and package them together in a single package and use Windows
APIs to communicate between them.
In Visual Studio 2017 version 15.4 and later, you can create a Windows Application Package Project to greatly
simplify the work of packaging your existing desktop application. A few restrictions apply with respect to what
registry calls or APIs your desktop application uses, but in many cases you can create alternate code paths to
achieve similar functionality while running in an app package. For more information, see Desktop Bridge.
Terminology
A Win32 application is a Windows desktop application in C++ that can make use of native Windows C
APIs and/or COM APIs CRT and Standard Library APIs, and 3rd party libraries. A Win32 application that
runs in a window requires the developer to work explicitly with Windows messages inside a Windows
procedure function. Despite the name, a Win32 application can be compiled as a 32-bit (x86) or 64-bit
(x64) binary. In the Visual Studio IDE, the terms x86 and Win32 are synonymous.
The Component Object Model (COM) is a specification that enables programs written in different
languages to communicate with one another. Many Windows components are implemented as COM
objects and follow standard COM rules for object creation, interface discovery and object destruction.
Using COM objects from C++ desktop applications is relatively straightforward, but writing your own
COM object is more advanced. The Active Template Library (ATL) provides macros and helper functions
that simplify COM development.
An MFC application is a Windows desktop application that use the Microsoft Foundation Classes to create
the user interface. An MFC application can also use COM components as well as CRT and Standard
Library APIs. MFC provides a thin C++ object-oriented wrapper over the window message loop and
Windows APIs. MFC is the default choice for applications—especially enterprise-type applications—that
have lots of user interface controls or custom user controls. MFC provides convenient helper classes for
window management, serialization, text manipulation, printing, and modern user interface elements such
as the ribbon. To be effective with MFC you should be familiar with Win32.
A C++/CLI application or component uses extensions to C++ syntax (as allowed by the C++ Standard) to
enable interaction between .NET and native C++code. A C++/CLI application can have parts that run
natively and parts that run on the .NET Framework with access to the .NET Base Class Library. C++/CLI is
the preferred option when you have native C++ code that needs to work with code written in C# or
Visual Basic. It is intended for use in .NET DLLs rather than in user interface code. For more information,
see .NET Programming with C++/CLI (Visual C++).
Any desktop application in C++ can use C Runtime (CRT) and Standard Library classes and functions, COM
objects, and the public Windows functions, which collectively are known as the Windows API. For an
introduction to Windows desktop applications in C++, see Get Started with Win32 and C++.
In this section
T IT L E DESC RIP T IO N
Windows Console Applications in C++ Contains information about console apps. A Win32 (or
Win64) console application has no window of its own and no
message loop. It runs in the console window, and input and
output are handled through the command line.
Walkthrough: Creating Windows Desktop Applications (C++) Create a simple Windows desktop application.
Creating an Empty Windows Desktop Application How to create a Windows desktop project that has no
default files.
Adding Files to an Empty Win32 Applications How to add files to an empty project.
Working with Resource Files How to add images, icons, string tables, and other resources
to a desktop application.
Resources for Creating a Game Using DirectX (C++) Links to content for creating games in C++.
Walkthrough: Creating and Using a Static Library How to create a .lib binary file.
How to: Use the Windows SDK in a Windows Desktop Contains steps for setting up your project to build using the
Application Windows SDK.
Related Articles
T IT L E DESC RIP T IO N
Windows Development Contains information about the Windows API and COM.
(Some Windows APIs and third-party DLLs are implemented
as COM objects.)
Hilo: Developing C++ Applications for Windows 7 Describes how to create a rich-client Windows desktop
application that uses Windows Animation and Direct2D to
create a carousel-based user interface. This tutorial has not
been updated since Windows 7 but it still provides a
thorough introduction to Win32 programming.
Overview of Windows Programming in C++ Describes key features of Windows desktop programming in
C++.
See also
C++ in Visual Studio
Walkthrough: Creating a Standard C++ Program
(C++)
7/27/2022 • 3 minutes to read • Edit Online
You can use Visual Studio to create Standard C++ programs. By following the steps in this walkthrough, you can
create a project, add a new file to the project, modify the file to add C++ code, and then compile and run the
program by using Visual Studio.
You can type your own C++ program or use one of the sample programs. The sample program in this
walkthrough is a console application. This application uses the set container in the C++ Standard Library.
NOTE
If conformance with a specific version of the C++ language standard (for example, C++14, C++17, or C++20) is required,
use the /std:c++14 , /std:c++17 , or /std:c++20 compiler option. (Visual Studio 2017 and later.)
Prerequisites
To complete this walkthrough, you must understand the fundamentals of the C++ language.
To create a project and add a source file
The following steps vary depending on which version of Visual Studio you are using. To see the documentation
for your preferred version of Visual Studio, use the Version selector control. It's found at the top of the table of
contents on this page.
To create a C++ project in Visual Studio
1. From the main menu, choose File > New > Project to open the Create a New Project dialog box.
2. At the top of the dialog, set Language to C++ , set Platform to Windows , and set Project type to
Console .
3. From the filtered list of project types, choose Console App then choose Next . In the next page, enter a
name for the project, and specify the project location if desired.
4. Choose the Create button to create the project.
To create a C++ project in Visual Studio 2017
1. Create a project by pointing to New on the File menu, and then clicking Project .
2. In the Visual C++ project types pane, click Windows Desktop , and then click Windows Console
Application .
3. Type a name for the project. By default, the solution that contains the project has the same name as the
project, but you can type a different name. You can also type a different location for the project.
4. Click OK to create the project.
To create a C++ project in Visual Studio 2015
1. Create a project by pointing to New on the File menu, and then clicking Project .
2. In the Visual C++ project types pane, click Windows Desktop , and then click Windows Console
Application .
3. In the New Project dialog box, expand Installed > Templates > Visual C++ , and then select Win32 .
In the center pane, select Win32 Console Application .
4. Type a name for the project. By default, the solution that contains the project has the same name as the
project, but you can type a different name. You can also type a different location for the project.
5. Click OK to create the project.
6. Complete the Win32 Application Wizard .
7. Click Next , then make sure Console Application is selected and uncheck the Precompiled Headers
box.
8. Click Finish .
Next Steps
Previous: Console Applications in Visual C++
Next: Walkthrough: Compiling a Native C++ Program on the Command Line
See also
C++ Language Reference
C++ Standard Library
Walkthrough: Create a traditional Windows Desktop
application (C++)
7/27/2022 • 14 minutes to read • Edit Online
This walkthrough shows how to create a traditional Windows desktop application in Visual Studio. The example
application you'll create uses the Windows API to display "Hello, Windows desktop!" in a window. You can use
the code that you develop in this walkthrough as a pattern to create other Windows desktop applications.
The Windows API (also known as the Win32 API, Windows Desktop API, and Windows Classic API) is a C-
language-based framework for creating Windows applications. It has been in existence since the 1980s and has
been used to create Windows applications for decades. More advanced and easier-to-program frameworks have
been built on top of the Windows API. For example, MFC, ATL, the .NET frameworks. Even the most modern
Windows Runtime code for UWP and Store apps written in C++/WinRT uses the Windows API underneath. For
more information about the Windows API, see Windows API Index. There are many ways to create Windows
applications, but the process above was the first.
IMPORTANT
For the sake of brevity, some code statements are omitted in the text. The Build the code section at the end of this
document shows the complete code.
Prerequisites
A computer that runs Microsoft Windows 7 or later versions. We recommend Windows 10 or later for the
best development experience.
A copy of Visual Studio. For information on how to download and install Visual Studio, see Install Visual
Studio. When you run the installer, make sure that the Desktop development with C++ workload is
checked. Don't worry if you didn't install this workload when you installed Visual Studio. You can run the
installer again and install it now.
An understanding of the basics of using the Visual Studio IDE. If you've used Windows desktop apps
before, you can probably keep up. For an introduction, see Visual Studio IDE feature tour.
An understanding of enough of the fundamentals of the C++ language to follow along. Don't worry, we
don't do anything too complicated.
7. In the Add New Item dialog box, select C++ File (.cpp) . In the Name box, type a name for the file, for
example, HelloWindowsDesktop.cpp. Choose Add .
Your project is now created and your source file is opened in the editor. To continue, skip ahead to Create the
code.
To create a Windows desktop project in Visual Studio 2017
1. On the File menu, choose New and then choose Project .
2. In the New Project dialog box, in the left pane, expand Installed > Visual C++ , then select Windows
Desktop . In the middle pane, select Windows Desktop Wizard .
In the Name box, type a name for the project, for example, DesktopApp. Choose OK .
3. In the Windows Desktop Project dialog, under Application type , select Windows application
(.exe) . Under Additional options , select Empty project . Make sure Precompiled Header isn't
selected. Choose OK to create the project.
4. In Solution Explorer , right-click the DesktopApp project, choose Add , and then choose New Item .
5. In the Add New Item dialog box, select C++ File (.cpp) . In the Name box, type a name for the file, for
example, HelloWindowsDesktop.cpp. Choose Add .
Your project is now created and your source file is opened in the editor. To continue, skip ahead to Create the
code.
To create a Windows desktop project in Visual Studio 2015
1. On the File menu, choose New and then choose Project .
2. In the New Project dialog box, in the left pane, expand Installed > Templates > Visual C++ , and then
select Win32 . In the middle pane, select Win32 Project .
In the Name box, type a name for the project, for example, DesktopApp. Choose OK .
3. On the Over view page of the Win32 Application Wizard , choose Next .
4. On the Application Settings page, under Application type , select Windows application . Under
Additional options , uncheck Precompiled header , then select Empty project . Choose Finish to
create the project.
5. In Solution Explorer , right-click the DesktopApp project, choose Add , and then choose New Item .
6. In the Add New Item dialog box, select C++ File (.cpp) . In the Name box, type a name for the file, for
example, HelloWindowsDesktop.cpp. Choose Add .
Your project is now created and your source file is opened in the editor.
Create the code
Next, you'll learn how to create the code for a Windows desktop application in Visual Studio.
To start a Windows desktop application
1. Just as every C application and C++ application must have a main function as its starting point, every
Windows desktop application must have a WinMain function. WinMain has the following syntax.
For information about the parameters and return value of this function, see WinMain entry point.
NOTE
What are all those extra words, such as WINAPI , or CALLBACK , or HINSTANCE , or _In_ ? The traditional
Windows API uses typedefs and preprocessor macros extensively to abstract away some of the details of types
and platform-specific code, such as calling conventions, __declspec declarations, and compiler pragmas. In
Visual Studio, you can use the IntelliSense Quick Info feature to see what these typedefs and macros define. Hover
your mouse over the word of interest, or select it and press Ctrl+K , Ctrl+I for a small pop-up window that
contains the definition. For more information, see Using IntelliSense. Parameters and return types often use SAL
Annotations to help you catch programming errors. For more information, see Using SAL Annotations to Reduce
C/C++ Code Defects.
2. Windows desktop programs require <windows.h> . <tchar.h> defines the TCHAR macro, which resolves
ultimately to wchar_t if the UNICODE symbol is defined in your project, otherwise it resolves to char . If
you always build with UNICODE enabled, you don't need TCHAR and can just use wchar_t directly.
#include <windows.h>
#include <tchar.h>
3. Along with the WinMain function, every Windows desktop application must also have a window-
procedure function. This function is typically named WndProc , but you can name it whatever you like.
WndProc has the following syntax.
In this function, you write code to handle messages that the application receives from Windows when
events occur. For example, if a user chooses an OK button in your application, Windows will send a
message to you and you can write code inside your WndProc function that does whatever work is
appropriate. It's called handling an event. You only handle the events that are relevant for your
application.
For more information, see Window Procedures.
To add functionality to the WinMain function
1. In the WinMain function, you populate a structure of type WNDCLASSEX. The structure contains
information about the window: the application icon, the background color of the window, the name to
display in the title bar, among other things. Importantly, it contains a function pointer to your window
procedure. The following example shows a typical WNDCLASSEX structure.
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
For information about the fields of the structure above, see WNDCLASSEX.
2. Register the WNDCLASSEX with Windows so that it knows about your window and how to send messages
to it. Use the RegisterClassEx function and pass the window class structure as an argument. The _T
macro is used because we use the TCHAR type.
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Windows Desktop Guided Tour"),
NULL);
return 1;
}
return 1;
}
This function returns an HWND , which is a handle to a window. A handle is somewhat like a pointer that
Windows uses to keep track of open windows. For more information, see Windows Data Types.
4. At this point, the window has been created, but we still need to tell Windows to make it visible. That's
what this code does:
The displayed window doesn't have much content because you haven't yet implemented the WndProc
function. In other words, the application isn't yet handling the messages that Windows is now sending to
it.
5. To handle the messages, we first add a message loop to listen for the messages that Windows sends.
When the application receives a message, this loop dispatches it to your WndProc function to be handled.
The message loop resembles the following code.
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
For more information about the structures and functions in the message loop, see MSG, GetMessage,
TranslateMessage, and DispatchMessage.
At this point, the WinMain function should resemble the following code.
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Windows Desktop Guided Tour"),
NULL);
return 1;
}
if (!hWnd)
{
MessageBox(NULL,
_T("Call to CreateWindow failed!"),
_T("Windows Desktop Guided Tour"),
NULL);
return 1;
}
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
}
HDC in the code is a handle to a device context, which is used to draw in the window's client area. Use the
BeginPaint and EndPaint functions to prepare for and complete the drawing in the client area.
BeginPaint returns a handle to the display device context used for drawing in the client area; EndPaint
ends the paint request and releases the device context.
2. An application typically handles many other messages. For example, WM_CREATE when a window is first
created, and WM_DESTROY when the window is closed. The following code shows a basic but complete
WndProc function.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
TCHAR greeting[] = _T("Hello, Windows desktop!");
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
Build the code
As promised, here's the complete code for the working application.
To build this example
1. Delete any code you've entered in HelloWindowsDesktop.cpp in the editor. Copy this example code and
then paste it into HelloWindowsDesktop.cpp:
// HelloWindowsDesktop.cpp
// compile with: /D_UNICODE /DUNICODE /DWIN32 /D_WINDOWS /c
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
// Global variables
// Stored instance handle for use in Win32 API calls such as FindResource
HINSTANCE hInst;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Windows Desktop Guided Tour"),
NULL);
return 1;
}
if (!hWnd)
{
MessageBox(NULL,
_T("Call to CreateWindow failed!"),
_T("Windows Desktop Guided Tour"),
NULL);
return 1;
}
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
2. On the Build menu, choose Build Solution . The results of the compilation should appear in the Output
window in Visual Studio.
3. To run the application, press F5 . A window that contains the text "Hello, Windows desktop!" should
appear in the upper-left corner of the display.
Congratulations! You've completed this walkthrough and built a traditional Windows desktop application.
See also
Windows Desktop Applications
Windows Desktop Wizard
7/27/2022 • 4 minutes to read • Edit Online
The Windows Desktop Wizard replaces the Win32 Application Wizard in Visual Studio 2017 and later. The
wizard allows you to create any of four types of C++ projects (listed in the heading in the table below). In each
case, you can specify additional options that are appropriate for the type of project you open.
The following table indicates which options are available for each application type.
EXEC UTA B L E
C O N SO L E ( W IN DO W S) DY N A M IC - L IN K
T Y P E O F SUP P O RT A P P L IC AT IO N A P P L IC AT IO N L IB RA RY STAT IC L IB RA RY
Precompiled No No No Yes
header
Overview
This wizard page describes the current project settings for the Win32 application you are creating. By default,
the following options are set:
The project is a Windows application.
The project is not empty.
The project contains no export symbols.
The project does not use a precompiled header file (this option is available for static library projects only).
The project includes support for neither MFC nor ATL.
Application type
Creates the specified application type.
O P T IO N DESC RIP T IO N
Dynamic Link Librar y Creates a Win32 dynamic-link library (DLL). A Win32 DLL is
a binary file, written in C or C++, that uses calls to the
Win32 API rather than to MFC classes, and that acts as a
shared library of functions that can be used simultaneously
by multiple applications.
Additional options
Defines the support and options for the application, depending on its type.
O P T IO N DESC RIP T IO N
Empty project Specifies that the project files are blank. If you have a set of
source code files (such as .cpp files, header files, icons,
toolbars, dialog boxes, and so on) and want to create a
project in the Visual C++ development environment, you
must first create a blank project, then add the files to the
project.
Precompiled header Specifies that the static library project uses a pre-compiled
header.
Security Development Lifecycle (SDL) checks For more information about SDL, see Microsoft Security
Development Lifecycle (SDL) Process Guidance
O P T IO N DESC RIP T IO N
ATL Builds into the project support for classes in the Active
Template Library (ATL). For Win32 console applications only.
Note This option does not indicate support for adding ATL
objects using the ATL code wizards. You can add ATL objects
only to ATL projects or MFC projects with ATL support.
MFC Builds into the project support for the Microsoft Foundation
Class (MFC) Library. For Win32 console applications and
static libraries only.
Remarks
Once you have created a Windows desktop application, you can add generic C++ classes using the Generic
Code Wizard. You can add other items, such as HTML files, header files, resources, or text files.
NOTE
You cannot add ATL classes, and you can add MFC classes only to those Windows desktop application types that support
MFC (see the previous table).
You can view the files the wizard creates for your project in Solution Explorer . For more information about the
files the wizard creates for your project, see the project-generated file, ReadMe.txt . For more information about
the file types, File Types Created for Visual Studio C++ projects.
See also
C++ project types in Visual Studio
ATL COM Desktop Components
7/27/2022 • 2 minutes to read • Edit Online
The ATL Reference documents the Active Template Library (ATL), a set of template-based C++ classes that
simplify the programming of Component Object Model (COM) objects. COM is a binary specification for
creating and consuming software components on Windows. To fully take advantage of ATL, a working familiarity
with COM is highly recommended. For more information about COM, see Component Object Model (COM).
In This Section
ATL Class Overview
Provides links to and brief descriptions of the ATL classes organized by category.
ATL Classes and structs
Provides reference material on the classes and structs organized alphabetically.
ATL Functions
Provides reference material on the global functions organized alphabetically. Includes topics organizing the
functions into categories.
ATL Global Variables
Provides reference material on the global variables organized alphabetically.
ATL Macros
Provides reference material on the macros organized alphabetically. Includes topics organizing the macros into
categories.
ATL Typedefs
Provides reference material on the typedefs organized alphabetically
Worker Archetype
Provides a links to the ATL Worker archetype.
Related Sections
ATL
Provides topics on how to program using the Active Template Library (ATL).
ATL Tutorial
Leads you through the creation of a control and demonstrates some ATL fundamentals in the process.
ATL Samples
Sample code that shows how to use ATL to write COM objects.
OLE DB Templates
Provides reference material for the OLE DB consumer and provider templates, a set of template classes that
implement many commonly used OLE DB interfaces.
MFC Desktop Applications
7/27/2022 • 2 minutes to read • Edit Online
The Microsoft Foundation Class (MFC) Library provides an object-oriented wrapper over much of the Win32
and COM APIs. Although it can be used to create very simple desktop applications, it is most useful when you
need to develop more complex user interfaces with multiple controls. You can use MFC to create applications
with Office-style user interfaces. For documentation on the Windows platform itself, see Windows
documentation. For information on building Windows applications in C++ without MFC, see Build desktop
Windows apps using the Win32 API.
The MFC Reference covers the classes, global functions, global variables, and macros that make up the Microsoft
Foundation Class Library.
The individual hierarchy charts included with each class are useful for locating base classes. The MFC Reference
usually does not describe inherited member functions or inherited operators. For information on these
functions, refer to the base classes depicted in the hierarchy diagrams.
The documentation for each class includes a class overview, a member summary by category, and topics for the
member functions, overloaded operators, and data members.
Public and protected class members are documented only when they are normally used in application programs
or derived classes. See the class header files for a complete listing of class members.
IMPORTANT
The MFC classes and their members cannot be used in applications that execute in the Windows Runtime environment.
MFC libraries (DLLs) for multibyte character encoding (MBCS) are no longer included in Visual Studio, but are available as
a Visual Studio add-on. For more information, see MFC MBCS DLL Add-on.
In This Section
Concepts
Conceptual articles on MFC topics.
Hierarchy Chart
Visually details the class relationships in the class library.
Class Overview
Lists the classes in the MFC Library according to category.
Walkthroughs
Contains articles that walk you through various tasks associated with MFC library features.
Technical Notes
Provides links to specialized topics, written by the MFC development team, on the class library.
Customization for MFC
Provides some tips for customizing your MFC application.
Classes
Provides links to and header file information for the MFC classes.
Internal Classes
Used internally in MFC. For completeness, this section describes these internal classes, but they are not intended
to be used directly in your code.
Macros and Globals
Provides links to the macros and global functions in the MFC Library.
Structures, Styles, Callbacks, and Message Maps
Provides links to the structures, styles, callbacks, and message maps used by the MFC Library.
MFC Wizards and Dialog Boxes
A guide to the features in Visual Studio for creating MFC applications.
Working with Resource Files
How to use resource files to manage static user interface data such as UI strings and dialog box layout.
Related Sections
Hierarchy Chart Categories
Describes the MFC hierarchy chart by category.
ATL/MFC Shared Classes
Provides links to classes that are shared between MFC and ATL.
MFC Samples
Provides links to samples that demonstrate how to use MFC.
Visual C++ Libraries Reference
Provides links to the various libraries provided with Visual C++, including ATL, MFC, OLE DB Templates, the C
run-time library, and the C++ Standard Library.
Debugging in Visual Studio
Provides links to using the Visual Studio debugger to correct logic errors in your application or stored
procedures.
See also
MFC and ATL
ATL/MFC Shared Classes
7/27/2022 • 2 minutes to read • Edit Online
These utility classes can be used in any native C++ project without requiring any MFC DLL.
In This Section
Classes Shared Between MFC and ATL
Provides links to the classes shared between MFC and ATL.
Related Sections
Active Template Library (ATL) Reference
Provides reference material for the ATL Library, a set of template-based C++ classes that simplify the
programming of COM objects.
Microsoft Foundation Class Library (MFC) Reference
Provides reference material for the MFC Library, a set of classes in that constitute an application framework,
which is the framework of an application written for the Windows API.
Debugging
Provides links to using the Visual Studio debugger to correct logic errors in your application or stored
procedures.
Text and Strings in Visual C++
7/27/2022 • 2 minutes to read • Edit Online
An important aspect of developing applications for international markets is the adequate representation of local
character sets. The ASCII character set defines characters in the range 0x00 to 0x7F. There are other character
sets, primarily European, that define the characters within the range 0x00 to 0x7F identically to the ASCII
character set and also define an extended character set from 0x80 to 0xFF. Thus, an 8-bit, single-byte-character
set (SBCS) is sufficient to represent the ASCII character set, as well as the character sets for many European
languages. However, some non-European character sets, such as Japanese Kanji, include many more characters
than a single-byte coding scheme can represent, and therefore require multibyte-character set (MBCS)
encoding.
In This Section
Unicode and MBCS
Discusses Visual C++ support for Unicode and MBCS programming.
Support for Unicode
Describes Unicode, a specification for supporting all character sets, including character sets that cannot be
represented in a single byte.
Support for Multibyte Character Sets (MBCS)
Discusses MBCS, an alternative to Unicode for supporting character sets, like Japanese and Chinese, that cannot
be represented in a single byte.
Generic-Text Mappings in tchar.h
Provides Microsoft-specific generic-text mappings for many data types, routines, and other objects.
How to: Convert Between Various String Types
Demonstrates how to convert various Visual C++ string types into other strings.
Related Sections
Internationalization
Discusses international support in the C run-time library.
International Samples
Provides links to samples demonstrating internationalization in Visual C++.
Language and Country/Region Strings
Provides the language and country/region strings in the C run-time library.
Resources for Creating a C++ Game Using DirectX
7/27/2022 • 2 minutes to read • Edit Online
To create the best desktop games, use Visual C++ and DirectX together.
Resources
Visual C++ is included in all editions of Visual Studio, but it's not installed by default. For information about how
to install Visual Studio and the C++ development tools, see Install C++ support in Visual Studio.
For Windows 8.1 and later, the DirectX SDK is included in the Windows SDK. You don't have to download
anything extra. For more information, see Where is the DirectX SDK?.
To create DirectX apps for Windows 7, Windows Vista, or Windows XP, you can download the stand-alone
DirectX SDK (Archive link).
DirectX Graphics and Gaming has information and samples to help you get started with DirectX programming.
Win32 Windows Applications contains articles that describe how to create a basic Windows desktop app.
Developing Games discusses Universal Windows Platform game development, but many of the concepts also
apply to desktop games.
How to: Use the Windows SDK in a Windows
Desktop application
7/27/2022 • 3 minutes to read • Edit Online
When you create a new classic Windows desktop project in Visual Studio, it targets the latest Windows SDK
installed by Visual Studio by default. Visual Studio installs a version of the SDK when you install the C++
Desktop workload. The Windows SDK supports writing code for Windows 7 SP1 and later. For more information
about targeting specific versions of Windows, see Using the Windows Headers and Update WINVER and
_WIN32_WINNT.
When you upgrade an existing project, you have a choice: You can keep using the target Windows SDK specified
in your project. Or, you can retarget your project to use the latest Windows SDK. With the latest Windows SDK,
you get the advantages of support for the latest operating systems and language standards.
4. Open the project properties dialog. In the Configuration Proper ties > General section, notice the
values of Windows Target Platform Version . Changing the value here has the same effect as
following this procedure. For more information, see General Property Page (Project).
This action changes the values of project macros that include paths to header files and library files. To see
what changed, open the Visual C++ Directories section of the Project Proper ties dialog. Select one
of the properties, such as Include Directories . Then, open the property value's dropdown list, and
choose <Edit> . The Include Directories dialog appears.
Choose the Macros >> button, and scroll down the list of macros to the Windows SDK macros to see all
the new values.
5. Repeat the retargeting procedure for other solution projects, as needed, and rebuild the solution.
To target the Windows 8.1 SDK
1. Open the shortcut menu for the project node in Solution Explorer, and choose Retarget projects . (In
earlier versions of Visual Studio, choose Retarget SDK Version .)
2. In the Target Platform Version dropdown list, choose 8.1 .
See also
Walkthrough: Create a traditional Windows Desktop application (C++)
Working with Resource Files
7/27/2022 • 2 minutes to read • Edit Online
WARNING
This section applies to Windows desktop applications written in C++.
For information about resources in Universal Windows Platform apps written in C++, see Defining App Resources, or on
adding resources to C++/CLI (managed) projects, see Resources in Desktop Apps in the .NET Framework Developer's
Guide.
NOTE
The Resource Editors and Resource View aren't available in Express editions.
To manually add resource files to managed projects, see Creating Resource Files for Desktop Apps. This article
includes how to access resources, display static resources, and assign resource strings to properties.
To globalize and localize resources in managed apps, see Globalizing and Localizing .NET Framework
Applications.
In This Section
Resource Files
Describes resource files and how they're used in Windows desktop applications. Also provides links to articles
that describe how to use resource files.
Resource Identifiers (Symbols)
Describes symbols and provides information on using the Resource Symbols dialog box to manage symbols
in your projects.
Resource Editors
Describes the resource editors provided in Visual Studio and the types of resources you can modify with each
editor. Also provides links to detailed information on using each editor.
Related Sections
C++ in Visual Studio
Provides links into the Visual C++ documentation.
Talk to Us
Provides links to information on using the documentation set, contacting product support, and employing
accessibility features.
See also
Windows Desktop Applications
Menus and Other Resources
Resource files (C++)
7/27/2022 • 3 minutes to read • Edit Online
NOTE
Since projects in .NET programming languages do not use resource script files, you must open your resources from
Solution Explorer . Use the Image editor and the Binary editor to work with resource files in managed projects.
Any managed resources you want to edit must be linked resources. The Visual Studio resource editors do not support
editing embedded resources.
The term resource file can refer to any of several file types, such as:
The resource script ( .rc ) file of a program.
A resource template ( .rct ) file.
An individual resource existing as a stand-alone file. This type includes a bitmap, icon, or cursor file that's
referred to from an .rc file.
A header file generated by the development environment. This type includes Resource.h , that's referred
to from an .rc file.
Other file types such as .exe , .dll , and .res files may also contain resources you can access, though the first
two aren't normally considered resource files.
You can work with resource files and resources from within your project. You can also work with resources and
resource files that aren't part of the current project, or that were created outside the development environment
of Visual Studio. For example, you can:
Work with nested and conditionally included resource files.
Update existing resources or convert them to Visual C++.
Import or export graphic resources to or from your current resource file.
Include shared or read-only identifiers (symbols) that can't be modified by the development environment.
Include resources in your executable ( .exe or .dll ) file that don't need editing (or shouldn't be edited),
such as shared resources between several projects.
Include resource types not supported by the development environment.
For more information on resources, see how to Create resources, Manage resources, and Include resources at
compile time.
Editable resources
The following types of files can be opened to edit the resources they contain:
F IL E N A M E DESC RIP T IO N
.bmp , .ico , .dib , .cur Bitmap, icon, toolbar, and cursor files
The Visual Studio environment works with and affects the following files when editing resources:
F IL E N A M E DESC RIP T IO N
Filename.aps Binary version of the current resource script file used for
quick loading.
Whenever the .aps file is out of synch with the .rc file,
the .rc file is regenerated. For example, when you Save ,
the resource editor overwrites the .rc file and the
resource.h file. Any changes to the resources themselves
remain incorporated in the .rc file, but comments are
always lost once the .rc file is overwritten. For information
on how to preserve comments, see Include resources at
compile time.
.rc Resource script file that contains script for the resources in
your current project. This file is overwritten by the .aps file
whenever you save.
Manifest resources
In C++ desktop projects, manifest resources are XML files that describe the dependencies an application uses.
For example, in Visual Studio, this MFC wizard-generated manifest file defines which version of the Windows
common control DLLs the application should use:
For a Windows XP or Windows Vista application, the manifest resource should specify the most current version
of the Windows common controls for the application to use. The example above uses version 6.0.0.0 , which
supports the Syslink control.
NOTE
You can only have one manifest resource per module.
To view the version and type information contained in a manifest resource, open the file in an XML viewer or the
Visual Studio text editor. If you open a manifest resource from Resource View, the resource will open in binary
format.
To open a manifest resource
1. Open your project in Visual Studio and navigate to Solution Explorer .
2. Expand the Resource Files folder, then:
To open in the text editor, double-click the .manifest file.
To open in another editor, right-click the .manifest file and select Open With . Specify the editor
to use and select Open .
Requirements
Win32
See also
Working with resource files
Resource identifiers (Symbols)
Resource editors
How to: Create Resources (C++)
7/27/2022 • 8 minutes to read • Edit Online
NOTE
This step is necessary before you add resources.
NOTE
You can only add a resource script file to an existing project loaded into the Visual Studio IDE. You can't create a
standalone resource script outside the project, though resource template (.rct) files can be created anytime.
NOTE
Don't confuse the project folder with the solution folder in Solution Explorer . If you put focus on the Solution
folder, you won't have the same Add New Item choices.
NOTE
Some commands are only available if the file is opened standalone, meaning outside of a project without first loading the
project. For example, to use the Save As command and save a file with a different format or file name, the file must be
opened standalone.
To open a resource script file outside of a project, in the menu, go to File > Open , and choose File .
Navigate to the resource script file, highlight the file, and choose Open .
NOTE
There may be times when you want to view the contents of your project's resource script file without using the
resource editors to open a resource. For example, you may want to search for a string across all dialog boxes in
the resource file without having to open each one separately. You can easily open the resource file in text format
to view all the resources it contains and complete global operations supported by the text editor.
To open a resource script file in text format, use the drop-down arrow on the right side of the Open button in the
above step and choose Open With . Select Source Code (Text) Editor and from the Open As drop-down list,
select Text and the resource opens in the Source Code editor.
To open multiple resource scripts follow the same step above for each file you want to open, for example,
Source1.rc and Source2.rc. Then, when both .rc files are open in separate documents windows, either use
the Window menu or right-click one of the files, and choose New Horizontal Tab Group or New
Ver tical Tab Group . The windows are now tiled so you can view them simultaneously.
TIP
You can open resource script files by right-clicking the .rc file in Solution Explorer , selecting Open with and choosing
Source Code (Text) Editor .
When you build a Microsoft Foundation Class (MFC) application for Windows using the MFC application wizard,
the wizard generates a basic set of files including a resource script (.rc) file) that contains the core features of the
MFC. However, these MFC-specific features aren't available when editing an .rc file for Windows applications not
based on MFC. This includes code wizards, menu prompt strings, list contents for combo box controls, and
ActiveX control hosting.
To add MFC support, with the resource script file open, in Resource View , highlight the resources folder
(for example, MFC.rc). Then in the Properties window, set MFC Mode to True .
NOTE
In addition to setting MFC Mode , the .rc file must be part of an MFC project. Only setting MFC Mode to True
on an .rc file in a Win32 project won't give you MFC features.
Create Resources
You can create a resource as a new default resource meaning a resource that isn't based on a template, or as a
resource patterned after a template.
Use the Resource View window to display resource files included in your projects. Expanding the top folder, for
example, Project1.rc, shows the resource types within that file. Expand each resource type to show the individual
resources of that type.
TIP
To open the Resource View window, go to menu View > Other Windows > Resource View or press Ctrl+Shift +E .
You can also use right-click on the Resource View window to launch a shortcut menu of commands, or double-
click the title bar to dock and undock the window. Right-click the title bar for commands that control the
behavior of the window. For more information, see Windows Management.
The Resource View windows includes the Add Resource dialog box with the following properties to add
resources to a C++ Windows desktop application project:
When you create a new resource, Visual C++ assigns a unique name to it, for example, IDD_Dialog1 . You can
customize this resource ID by editing the resource properties either in the associated resource editor or in the
Properties window.
NOTE
Don't specify a resource name or ID that is reserved by Visual Studio. Reserved names are DESIGNINFO , HWB , and
TEXTINCLUDE , and the reserved ID is 255 .
To create a resource
In Resource View , select your .rc file, then use Edit > Add Resource and choose the type of resource to
add to your project.
TIP
You can also right-click the .rc file in Resource View and choose Add Resource from the shortcut menu.
In Solution Explorer , right-click the project folder, select Add > Add Resource and choose the type of
resource to add to your project.
NOTE
If you don't already have an .rc file in your project, this step will create one. You can then repeat this step to add
specific resource types to the new .rc file.
In Class View, right-click the project, select Add > Add Resource and choose the type of resource to add
to your project.
Use the menu Project > Add Resource .
NOTE
The resource editor automatically provides a unique resource ID. You can revise the resource properties as needed.
NOTE
Place language-specific template files in subdirectories of the main template directory. For example, English-only template
files go in ..\<resource template directory>\1033.
Visual Studio searches for new .rct files in \Program Files\Microsoft Visual Studio <version>\VC\VCResourceTemplates,
\Program Files\Microsoft Visual Studio <version>\VC\VCResourceTemplates\<LCID> (such as an LCID of 1033 for
English), or anywhere on the include path. If you prefer to store your .rct files in another location, you must add the
location to the include path.
Requirements
Win32
See also
Resource Files
How to: Manage Resources
How to: Include Resources at Compile Time
How to: Manage Resources (C++)
7/27/2022 • 3 minutes to read • Edit Online
NOTE
Visual C++ includes sample resource files that you can use in your own application. For more information, see CLIPART:
Common Resources.
You can't drag and drop, copy, cut, or paste between resource files in the project (Resource View ) and stand-
alone .rc files open in document windows. You could do this in previous versions of the product. Only use the
drag-and-drop method between .rc files that are open outside of the project.
To copy resources
1. Open both resource files stand-alone. (See Use resource script files). For example, open Source1.rc and
Source2.rc.
2. Inside the first .rc file, either:
Use the drag-and-drop method
a. Select the resource you wish to copy. For example, in Source1.rc, select IDD_DIALOG1 .
b. Hold down the Ctrl key and drag the resource to the second .rc file. For example, drag
IDD_DIALOG1 from Source1.rc to Source2.rc.
TIP
Dragging the resource without holding down the Ctrl key moves the resource rather than copying
it.
NOTE
To avoid conflicts with symbol names or values in the existing file, Visual C++ may change the transferred resource's
symbol value or symbol name and value when you copy it to the new file.
While copying in a resource, you can change its language property or condition property, or both.
The language of a resource specifies the language used by FindResource to help identify the resource for
which you're looking. Resources can have differences for each language that aren't related to text, for
example, accelerators that might only work on a Japanese keyboard or a bitmap that would only be
appropriate for Chinese localized builds.
The condition of a resource is a defined symbol that identifies a condition under which this particular
copy of the resource is to be used.
The language and condition of a resource are shown in parentheses after the name of the resource in the
Workspace window. Here the resource named IDD_AboutBox is using Finnish as its language and its condition
is XX33 :
NOTE
Resource types such as accelerators, dialog boxes, and string tables can't be imported or exported because they're not
stand-alone file types.
NOTE
The import process works the same no matter which resource type you have selected. The imported resource is
automatically added to the correct node of that resource type.
Requirements
Win32
See also
Resource Files
How to: Create Resources
How to: Include Resources at Compile Time
How to: Include Resources at Compile Time (C++)
7/27/2022 • 3 minutes to read • Edit Online
By default all resources are located in one resource script (.rc) file, however there are many reasons to place
resources in a file other than the main .rc file:
To add comments to resource statements that won't get deleted when you save the .rc file.
To include resources that have already been developed and tested and don't need further modification.
Any files that are included but don't have an .rc extension won't be editable by the resource editors.
To include resources that are being used by different projects, or that are part of a source code version-
control system. These resources must exist in a central location where modifications will affect all
projects.
To include resources (such as RCDATA resources) that are a custom format. RCDATA resources have
special requirements where you can't use an expression as a value for the nameID field.
If you have sections in your existing .rc files that meet any of these conditions, place these sections in one or
more separate .rc files and include them in your project using the Resource Includes dialog box.
Resource Includes
You can add resources from other files to your project at compile time by listing them in the Compile-time
directives box in the Resource Includes dialog box. Use the Resource Includes dialog box to modify the
project environment's normal working arrangement of storing all resources in the project .rc file and all symbols
in Resource.h .
To get started, open the Resource Includes dialog box by right-clicking an .rc file in Resource View, select
Resource Includes and note the following properties:
Symbol header file Allows you to change the name of the header file where
symbol definitions for your resource files are stored.
Read-only symbol directives Enables you to include header files that contain symbols that
shouldn't be modified.
Compile-time directives Allows you to include resource files that are created and
edited separately from the resources in your main resource
file, contain compile-time directives (such as those directives
that conditionally include resources), or contain resources in
a custom format.
Once changes are made to your resource file using the Resource Includes dialog box, you must close and
reopen the .rc file for the changes to take effect.
To include resources in your project at compile time
1. Place the resources in a resource script file with a unique file name. Don't use projectname.rc, because
this is the name of the file used for the main resource script file.
2. Right-click the .rc file in Resource View and select Resource Includes .
3. In the Compile-time directives box, add the #include compiler directive to include the new resource
file in the main resource file in the development environment.
The resources in files included this way are only made part of the executable at compile time and aren't available
for editing or modification when you're working on your project's main .rc file. Included .rc files need to be
opened separately and any files included without the .rc extension won't be editable by the resource editors.
To specify include directories for a specific resource (.rc) file
1. Right-click the .rc file in Solution Explorer and select Proper ties .
2. Select the Resources node in the left pane and specify any additional include directories in the
Additional include directories property.
To find symbols in resources
1. Go to menu Edit > Find Symbol.
TIP
To use regular expressions in your search, select Find in Files in the Edit menu instead of Find Symbol. Select the
Use: Regular Expressions check box in the Find dialog box and in the Find What box you can choose a regular
search expression from the drop-down list. When you select an expression from this list, it's substituted as the
search text in the Find What box.
2. In the Find What box, select a previous search string from the drop-down list or type the accelerator key
you want to find, for example, ID_ACCEL1 .
3. Select any of the Find options and choose Find Next .
NOTE
You cannot search for symbols in string, accelerator, or binary resources.
Requirements
Win32
See also
Resource Files
How to: Create Resources
How to: Manage Resources
Resource Identifiers (Symbols) (C++)
7/27/2022 • 2 minutes to read • Edit Online
A symbol is a resource identifier (ID) that consists of two parts, a symbol name (text string) mapped to a symbol
value (integer), for example:
IDC_EDITNAME = 5100
NOTE
When you are copying resources or resource objects from one .rc file to another, Visual C++ may change the transferred
resource's symbol value, or symbol name and value, to avoid conflicts with symbol names or values in the existing file.
Requirements
Win32
See also
Working with Resource Files
Resource Files
Resource Editors
How to: Create Symbols (C++)
7/27/2022 • 2 minutes to read • Edit Online
When you're beginning a new project, you may find it convenient to map out the symbol names you need
before creating the resources to which they'll be assigned.
NOTE
If your project doesn't already contain an .rc file, see How to: Create Resources.
The Resource Symbols dialog box allows you to add new resource symbols, change the symbols that are
displayed, or skip to the location in the source code where a symbol is in use.
The dialog box contains the following properties:
New Opens the New Symbol dialog box that enables you to
define the name and, if necessary, a value for a new symbolic
resource identifier.
Change Opens the Change Symbol dialog box that allows you to
change the name or value of a symbol.
View Use Opens the resource that contains the symbol in the
corresponding resource editor.
Create Symbols
To create a new symbol
1. In the Resource Symbols dialog box, choose New .
2. In the Name box, type a symbol name.
3. Accept the assigned symbol value or type a new value in the Value box.
4. Select OK to add the new symbol to the symbol list.
NOTE
If you type a symbol name that already exists, a message box appears stating that a symbol with that name is already
defined. You can't define two or more symbols with the same name, but you can define different symbols with the same
numeric value.
NOTE
To see predefined symbols, check the Show read-only symbols check box.
Requirements
Win32
See also
Resource Identifiers (Symbols)
How to: Manage Symbols
Predefined Symbol IDs
How to: Manage Symbols
7/27/2022 • 6 minutes to read • Edit Online
When you create a new resource or resource object, the development environment assigns it a default symbol
name, for example, IDD_DIALOG1 . You can use the Properties window to change the default symbol name or to
change the name of any symbol already associated with a resource.
For symbols associated with a single resource, you can also use the Proper ties window to change the symbol
value. You can use the Resource Symbols dialog box to change the value of symbols not currently assigned to a
resource.
Normally all symbol definitions are saved in Resource.h . However, you may need to change this include
filename so that you can, for example, work with more than one resource file in the same directory.
NOTE
If your project doesn't already contain an .rc file, see How to: Create Resources.
NOTE
If you don't follow the standard symbol name scheme (ID*_[keyword]) outlined below and your symbol name happens to
be the same as a keyword known to the resource script compiler, trying to build the resource script file will result in
seemingly random error generation that is difficult to diagnose. To prevent this, adhere to the standard naming scheme.
Symbol names have descriptive prefixes that indicate the kind of resource or object they represent. These
descriptive prefixes begin with the text combination ID. The Microsoft Foundation Class (MFC) library uses the
symbol naming conventions shown in the following table:
Resources IDR_, IDD_, IDC_, IDI_, IDB_ Accelerator or menu (and associated or
custom resources), dialog box, cursor,
icon, bitmap
NOTE
You can use the Resource Symbols dialog box to change the names of symbols not currently assigned to a resource.
18
4001
0x0012
-3456
Symbol values for resources such as accelerators, bitmaps, cursors, dialog boxes, icons, menus, string tables, and
version information, must be decimal numbers in the range from 0 to 32,767 but can't be hexadecimal. Symbol
values for parts of resources, such as dialog box controls or individual strings in the string table, can be from 0
to 65,534 or from -32,768 to 32,767. For more information on number ranges, see TN023: Standard MFC
Resources.
Resource symbols are 16-bit numbers. You may enter them as signed or unsigned, however, they're used
internally as unsigned integers, so negative numbers will be cast to their corresponding positive value.
Some limitations of symbol values are:
The Visual Studio development environment and MFC use some number ranges for special purposes. All
numbers with the most significant bit set (-32,768 to -1 or 32,768 to 65,534, depending on sign) are
reserved by MFC.
You can't define a symbol value using other symbol strings. For example, the following symbol definition
isn't supported:
#define IDC_MYEDIT IDC_OTHEREDIT //not supported
You can't use preprocessor macros with arguments as value definitions. The following example isn't a
valid expression regardless of what ID evaluates to at compile time:
Your application may have an existing file containing symbols defined with expressions.
To change a symbol value
1. In Resource View, select the resource.
2. In the Proper ties window, type the symbol name followed by an equal sign and an integer in the ID box,
for example:
IDC_EDITNAME=5100
The new value is stored in the symbol header file the next time you save the project. Only the symbol
name remains visible in the ID box and the equal sign and value aren't displayed after they're validated.
NOTE
To change a symbol that's assigned to a resource or object, you must use the resource editor or Proper ties window.
NOTE
Before deleting an unused symbol in a resource file, make sure it's not used elsewhere in the program or by resource files
included at compile time.
Include Symbols
The first time the development environment reads a resource file created by another application, it marks all
included header files as read-only. Though you can use the Resource Includes dialog box to add additional read-
only symbol header files.
One reason you may want to use read-only symbol definitions is for symbol files that you plan to share among
several projects.
You can also use included symbol files when you have existing resources with symbol definitions that use
expressions rather than simple integers to define the symbol value. For example:
The environment will correctly interpret these calculated symbols as long as:
The calculated symbols are placed in a read-only symbols file.
Your resource file contains resources to which these calculated symbols are already assigned.
A numeric expression is expected.
NOTE
If a string or a numeric expression is expected, then the expression is not evaluated.
NOTE
What you type in the Read-Only symbol directives box is included in the resource file exactly as you type it.
Make sure what you type does not contain any spelling or syntax errors.
Use the Read-only symbol directives box to include files with symbol definitions only. Don't include
resource definitions, else duplicate resource definitions will be created when the file is saved.
3. Place the symbols in the file you specified.
The symbols in files included in this way are evaluated each time you open your resource file, but they
aren't replaced on the disk when you save your file.
4. Select OK .
To change the name of the resource symbol header file
1. In Resource View, right-click your .rc file and choose Resource Includes.
2. In the Symbol header file box, type the new name for the include file.
Requirements
Win32
See also
Resource Identifiers (Symbols)
How to: Create Symbols
Predefined Symbol IDs
Predefined Symbol IDs
7/27/2022 • 2 minutes to read • Edit Online
When you begin a new project, depending on the project type, some symbol IDs are predefined for your use.
These symbol IDs support the various libraries and project types such as MFC. They represent common tasks
that are usually included in any application, or actions of hardware items, such as a mouse or printer.
These symbol IDs become important when working with resources. They are available when you edit accelerator
tables and some of them are already associated with virtual keys. They're also available to you through the
Properties window. You can assign any of the predefined symbol IDs to new resources, or you can assign
accelerator keys to them and the functionality associated with the symbol ID automatically associates with that
key combination.
Libraries have predefined symbols that will appear as part of the project:
ATL Predefined Symbols
MFC Predefined Symbols
Win32 Predefined Symbols
NOTE
Predefined symbols are always read-only.
Requirements
Win32, MFC, or ATL
See also
Resource Identifiers (Symbols)
How to: Create Symbols
How to: Manage Symbols
ATL Predefined Symbols
7/27/2022 • 2 minutes to read • Edit Online
These symbols are defined in the ATL header files, but they support standard Windows application functions and
actions. These symbols are mainly used with dialog boxes.
When you are working with dialogs and controls in the Dialog Editor, these symbols will appear in the
Properties window associated with common controls. For instance, if your dialog box has a Cancel button, that
command will be associated with the symbol IDCANCEL in the Proper ties window.
Requirements
ATL
See also
Predefined Symbol IDs
MFC Predefined Symbols
Win32 Predefined Symbols
MFC Predefined Symbols
7/27/2022 • 3 minutes to read • Edit Online
MFC projects always include several header files that support windows. These are added via #include
statements in the StdAfx.h file:
The header files include symbol ID values for MFC common values. These symbols are only available when
you're working in an MFC project. The AFX_ prefix is followed by the standard symbol name prefixes.
AFX_ID_PREVIEW_CLOSE
AFX_ID_PREVIEW_NEXT
AFX_ID_PREVIEW_NUMPAGE
AFX_ID_PREVIEW_PREV
AFX_ID_PREVIEW_PRINT
AFX_ID_PREVIEW_ZOOMIN
AFX_ID_PREVIEW_ZOOMOUT
AFX_IDB_CHECKLISTBOX_95
AFX_IDB_MINIFRAME_MENU
AFX_IDC_BROWSE
AFX_IDC_BROWSER
AFX_IDC_CHANGE
AFX_IDC_CLEAR
AFX_IDC_COLOR_BLACK
AFX_IDC_COLOR_BLUE
AFX_IDC_COLOR_CYAN
AFX_IDC_COLOR_DARKBLUE
AFX_IDC_COLOR_DARKCYAN
AFX_IDC_COLOR_DARKGREEN
AFX_IDC_COLOR_DARKMAGENTA
AFX_IDC_COLOR_DARKRED
AFX_IDC_COLOR_GRAY
AFX_IDC_COLOR_GREEN
AFX_IDC_COLOR_LIGHTBROWN
AFX_IDC_COLOR_LIGHTGRAY
AFX_IDC_COLOR_MAGENTA
AFX_IDC_COLOR_RED
AFX_IDC_COLOR_WHITE
AFX_IDC_COLOR_YELLOW
AFX_IDC_COLORPROP
AFX_IDC_CONTEXTHELP
AFX_IDC_FONTNAMES
AFX_IDC_FONTPROP
AFX_IDC_FONTSIZES
AFX_IDC_FONTSTYLES
AFX_IDC_HSPLITBAR
AFX_IDC_LISTBOX
AFX_IDC_MAGNIFY
AFX_IDC_MOUSE_MASK
AFX_IDC_MOUSE_ORG_HORZ
AFX_IDC_MOUSE_ORG_HV
AFX_IDC_MOUSE_ORG_VERT
AFX_IDC_MOUSE_PAN_E
AFX_IDC_MOUSE_PAN_HORZ
AFX_IDC_MOUSE_PAN_HV
AFX_IDC_MOUSE_PAN_N
AFX_IDC_MOUSE_PAN_NE
AFX_IDC_MOUSE_PAN_NW
AFX_IDC_MOUSE_PAN_S
AFX_IDC_MOUSE_PAN_SE
AFX_IDC_MOUSE_PAN_SW
AFX_IDC_MOUSE_PAN_VERT
AFX_IDC_MOUSE_PAN_W
AFX_IDC_MOVE4WAY
AFX_IDC_NODROPCRSR
AFX_IDC_PICTURE
AFX_IDC_PRINT_DOCNAME
AFX_IDC_PRINT_PAGENUM
AFX_IDC_PRINT_PORTNAME
AFX_IDC_PRINT_PRINTERNAME
AFX_IDC_PROPNAME
AFX_IDC_SAMPLEBOX
AFX_IDC_SMALLARROWS
AFX_IDC_STRIKEOUT
AFX_IDC_SYSTEMCOLORS
AFX_IDC_TAB_CONTROL
AFX_IDC_TRACK4WAY
AFX_IDC_TRACKNESW
AFX_IDC_TRACKNS
AFX_IDC_TRACKNWSE
AFX_IDC_TRACKWE
AFX_IDC_UNDERLINE
AFX_IDC_VSPLITBAR
AFX_IDD_BUSY
AFX_IDD_CHANGEICON
AFX_IDD_CHANGESOURCE
AFX_IDD_CONVERT
AFX_IDD_EDITLINKS
AFX_IDD_FILEBROWSE
AFX_IDD_INSERTOBJECT
AFX_IDD_NEWTYPEDLG
AFX_IDD_OBJECTPROPERTIES
AFX_IDD_PASTESPECIAL
AFX_IDD_PREVIEW_TOOLBAR
AFX_IDD_PRINTDLG
AFX_IDD_PROPPAGE_COLOR
AFX_IDD_PROPPAGE_FONT
AFX_IDD_PROPPAGE_PICTURE
AFX_IDI_STD_FRAME
AFX_IDI_STD_MDIFRAME
AFX_IDP_ARCH_BADCLASS
AFX_IDP_ARCH_BADINDEX
AFX_IDP_ARCH_BADSCHEMA
AFX_IDP_ARCH_ENDOFFILE
AFX_IDP_ARCH_GENERIC
AFX_IDP_ARCH_NONE
AFX_IDP_ARCH_READONLY
AFX_IDP_ARCH_WRITEONLY
AFX_IDP_ASK_TO_DISCARD
AFX_IDP_ASK_TO_SAVE
AFX_IDP_ASK_TO_UPDATE
AFX_IDP_BAD_VERB
AFX_IDP_COMMAND_FAILURE
AFX_IDP_DAO_BADBINDINFO
AFX_IDP_DAO_COLUMNUNAVAILABLE
AFX_IDP_DAO_DFX_BIND
AFX_IDP_DAO_ENGINE_INITIALIZATION
AFX_IDP_DAO_OBJECT_NOT_OPEN
AFX_IDP_DAO_ROWTOOSHORT
AFX_IDP_DLL_BAD_VERSION
AFX_IDP_DLL_LOAD_FAILED
AFX_IDP_E_BADFILEMODE
AFX_IDP_E_BADFILENAME
AFX_IDP_E_BADFILENAMEORNUMBER
AFX_IDP_E_BADRECORDLENGTH
AFX_IDP_E_BADREDORDNUMBER
AFX_IDP_E_CANTSAVEFILETOEMP
AFX_IDP_E_DEVICEIOERROR
AFX_IDP_E_DEVICEUNAVAILABLE
AFX_IDP_E_DISKFULL
AFX_IDP_E_DISKNOTREADY
AFX_IDP_E_DIVISIONBYZERO
AFX_IDP_E_FILEALREADYEXISTS
AFX_IDP_E_FILEALREADYOPEN
AFX_IDP_E_FILENOTFOUND
AFX_IDP_E_GETNOTSUPPORTED
AFX_IDP_E_GETNOTSUPPORTEDATRUNTIME
AFX_IDP_E_ILLEGALFUNCTIONCALL
AFX_IDP_E_INVALIDCLIPBOARDFORMAT
AFX_IDP_E_INVALIDFILEFORMAT
AFX_IDP_E_INVALIDPATTERNSTRING
AFX_IDP_E_INVALIDPICTURE
AFX_IDP_E_INVALIDPROPERTYARRAYINDEX
AFX_IDP_E_INVALIDPROPERTYVALUE
AFX_IDP_E_INVALIDUSEOFNULL
AFX_IDP_E_NEEDPROPERTYARRAYINDEX
AFX_IDP_E_OUTOFMEMORY
AFX_IDP_E_OUTOFSTACKSPACE
AFX_IDP_E_OVERFLOW
AFX_IDP_E_PATHFILEACCESSERROR
AFX_IDP_E_PATHNOTTFOUND
AFX_IDP_E_PERMISSIONDENIED
AFX_IDP_E_PRINTERERROR
AFX_IDP_E_PROPERTYNOTFOUND
AFX_IDP_E_REPLACEMENTSTOOLONG
AFX_IDP_E_SEARCHTEXTNOTFOUND
AFX_IDP_E_SETNOTPERMITTED
AFX_IDP_E_SETNOTSUPPORTED
AFX_IDP_E_SETNOTSUPPORTEDATRUNTIME
AFX_IDP_E_TOOMANYFILES
AFX_IDP_FAILED_ACCESS_READ
AFX_IDP_FAILED_ACCESS_WRITE
AFX_IDP_FAILED_DISK_FULL
AFX_IDP_FAILED_INVALID_FORMAT
AFX_IDP_FAILED_INVALID_PATH
AFX_IDP_FAILED_IO_ERROR_READ
AFX_IDP_FAILED_IO_ERROR_WRITE
AFX_IDP_FAILED_MAPI_LOAD
AFX_IDP_FAILED_MAPI_SEND
AFX_IDP_FAILED_MEMORY_ALLOC
AFX_IDP_FAILED_TO_AUTO_REGISTER
AFX_IDP_FAILED_TO_CONNECT
AFX_IDP_FAILED_TO_CONVERT
AFX_IDP_FAILED_TO_CREATE_DOC
AFX_IDP_FAILED_TO_CREATE
AFX_IDP_FAILED_TO_LAUNCH_HELP
AFX_IDP_FAILED_TO_LAUNCH
AFX_IDP_FAILED_TO_NOTIFY
AFX_IDP_FAILED_TO_OPEN_DOC
AFX_IDP_FAILED_TO_REGISTER
AFX_IDP_FAILED_TO_SAVE_DOC
AFX_IDP_FAILED_TO_START_PRINT
AFX_IDP_FAILED_TO_UPDATE
AFX_IDP_FILE_ACCESS_DENIED
AFX_IDP_FILE_BAD_PATH
AFX_IDP_FILE_BAD_SEEK
AFX_IDP_FILE_DIR_FULL
AFX_IDP_FILE_DISKFULL
AFX_IDP_FILE_EOF
AFX_IDP_FILE_GENERIC
AFX_IDP_FILE_HARD_IO
AFX_IDP_FILE_INVALID_FILE
AFX_IDP_FILE_LOCKING
AFX_IDP_FILE_NONE
AFX_IDP_FILE_NOT_FOUND
AFX_IDP_FILE_REMOVE_CURRENT
AFX_IDP_FILE_SHARING
AFX_IDP_FILE_TOO_LARGE
AFX_IDP_FILE_TOO_MANY_OPEN
AFX_IDP_GET_NOT_SUPPORTED
AFX_IDP_INTERNAL_FAILURE
AFX_IDP_INVALID_FILENAME
AFX_IDP_INVALID_MAPI_DLL
AFX_IDP_NO_ERROR_AVAILABLE
AFX_IDP_PARSE_BYTE
AFX_IDP_PARSE_CURRENCY
AFX_IDP_PARSE_DATE
AFX_IDP_PARSE_DATETIME
AFX_IDP_PARSE_GUID
AFX_IDP_PARSE_INT_RANGE
AFX_IDP_PARSE_INT
AFX_IDP_PARSE_RADIO_BUTTON
AFX_IDP_PARSE_REAL_RANGE
AFX_IDP_PARSE_REAL
AFX_IDP_PARSE_STRING_SIZE
AFX_IDP_PARSE_TIME
AFX_IDP_PARSE_UINT
AFX_IDP_PICTURECANTLOAD
AFX_IDP_PICTURECANTOPEN
AFX_IDP_PICTUREREADFAILED
AFX_IDP_PICTURETOOLARGE
AFX_IDP_SCRIPT_DISPATCH_EXCEPTION
AFX_IDP_SCRIPT_ERROR
AFX_IDP_SERVER_BUSY
AFX_IDP_SET_NOT_SUPPORTED
AFX_IDP_STATIC_OBJECT
AFX_IDP_UNREG_DONE
AFX_IDP_UNREG_FAILURE
AFX_IDR_PREVIEW_ACCEL
AFX_IDS_ACTIVATE_VERB
AFX_IDS_ALL_FILES
AFX_IDS_ALLFILTER
AFX_IDS_APP_TITLE_EMBEDDING
AFX_IDS_APP_TITLE
AFX_IDS_AUTO
AFX_IDS_AUTOSAVE_RECOVERED
AFX_IDS_AUTOSAVE_RECOVERY_ASK_1
AFX_IDS_AUTOSAVE_RECOVERY_ASK_2
AFX_IDS_AUTOSAVE_RECOVERY_ASK_3
AFX_IDS_AUTOSAVE_RECOVERY_ASK_4
AFX_IDS_AUTOSAVE_RECOVERY_ASK_5
AFX_IDS_AUTOSAVE_RECOVERY_ASK_6
AFX_IDS_BITMAP_FORMAT
AFX_IDS_BOLD
AFX_IDS_BOLDITALIC
AFX_IDS_BORDERSTYLE_0
AFX_IDS_BORDERSTYLE_1
AFX_IDS_CHANGE_LINK
AFX_IDS_CHECKLISTBOX_CHECK
AFX_IDS_CHECKLISTBOX_MIXED
AFX_IDS_CHECKLISTBOX_UNCHECK
AFX_IDS_COLOR_ACTIVEBAR
AFX_IDS_COLOR_ACTIVEBORDER
AFX_IDS_COLOR_ACTIVETEXT
AFX_IDS_COLOR_APPWORKSPACE
AFX_IDS_COLOR_BTNFACE
AFX_IDS_COLOR_BTNHIGHLIGHT
AFX_IDS_COLOR_BTNSHADOW
AFX_IDS_COLOR_BTNTEXT
AFX_IDS_COLOR_DESKTOP
AFX_IDS_COLOR_DISABLEDTEXT
AFX_IDS_COLOR_HIGHLIGHT
AFX_IDS_COLOR_HIGHTLIGHTTEXT
AFX_IDS_COLOR_INACTIVEBAR
AFX_IDS_COLOR_INACTIVEBORDER
AFX_IDS_COLOR_INACTIVETEXT
AFX_IDS_COLOR_MENUBAR
AFX_IDS_COLOR_MENUTEXT
AFX_IDS_COLOR_PPG_CAPTION
AFX_IDS_COLOR_PPG
AFX_IDS_COLOR_SCROLLBARS
AFX_IDS_COLOR_WNDBACKGND
AFX_IDS_COLOR_WNDFRAME
AFX_IDS_COLOR_WNDTEXT
AFX_IDS_COMPANY_NAME
AFX_IDS_DELETED
AFX_IDS_DESKACCESSORY
AFX_IDS_DISPLAYSTRING_COLOR
AFX_IDS_DISPLAYSTRING_FONT
AFX_IDS_DISPLAYSTRING_PICTURE
AFX_IDS_EDIT_VERB
AFX_IDS_EMBED_FORMAT
AFX_IDS_EXIT_MENU
AFX_IDS_FONT_PPG_CAPTION
AFX_IDS_FONT_PPG
AFX_IDS_FROZEN
AFX_IDS_HELPMODEMESSAGE
AFX_IDS_HIDE
AFX_IDS_HTTP_AUTH_REQUIRED
AFX_IDS_HTTP_BAD_REQUEST
AFX_IDS_HTTP_FORBIDDEN
AFX_IDS_HTTP_NO_TEXT
AFX_IDS_HTTP_NOT_FOUND
AFX_IDS_HTTP_NOT_IMPLEMENTED
AFX_IDS_HTTP_SERVER_ERROR
AFX_IDS_HTTP_TITLE
AFX_IDS_IDLEMESSAGE
AFX_IDS_INVALID_CURRENCY
AFX_IDS_INVALID_DATETIME
AFX_IDS_INVALID_DATETIMESPAN
AFX_IDS_ITALIC
AFX_IDS_LINKSOURCE_FORMAT
AFX_IDS_MANUAL
AFX_IDS_MDICHILD
AFX_IDS_MEMORY_EXCEPTION
AFX_IDS_METAFILE_FORMAT
AFX_IDS_MINI_FONT
AFX_IDS_NOT_DOCOBJECT
AFX_IDS_NOT_SUPPORTED_EXCEPTION
AFX_IDS_OBJ_TITLE_INPLACE
AFX_IDS_OBJECT_MENUITEM
AFX_IDS_OCC_SCALEUNITS_PIXELS
AFX_IDS_ONEPAGE
AFX_IDS_OPENFILE
AFX_IDS_PASTELINKEDTYPE
AFX_IDS_PICTURE_PPG_CAPTION
AFX_IDS_PICTURE_PPG
AFX_IDS_PICTUREBROWSETITLE
AFX_IDS_PICTUREFILTER
AFX_IDS_PICTYPE_BITMAP
AFX_IDS_PICTYPE_ICON
AFX_IDS_PICTYPE_METAFILE
AFX_IDS_PICTYPE_NONE
AFX_IDS_PICTYPE_UNKNOWN
AFX_IDS_PREVIEW_CLOSE
AFX_IDS_PREVIEWPAGEDESC
AFX_IDS_PRINTCAPTION
AFX_IDS_PRINTDEFAULT
AFX_IDS_PRINTDEFAULTEXT
AFX_IDS_PRINTFILTER
AFX_IDS_PRINTONPORT
AFX_IDS_PRINTPAGENUM
AFX_IDS_PRINTTOFILE
AFX_IDS_PROPPAGE_UNKNOWN
AFX_IDS_REGULAR
AFX_IDS_RESOURCE_EXCEPTION
AFX_IDS_RTF_FORMAT
AFX_IDS_SAMPLETEXT
AFX_IDS_SAVE_AS_MENU
AFX_IDS_SAVE_COPY_AS_MENU
AFX_IDS_SAVE_MENU
AFX_IDS_SAVEFILE
AFX_IDS_SAVEFILECOPY
AFX_IDS_SCCLOSE
AFX_IDS_SCMAXIMIZE
AFX_IDS_SCMINIMIZE
AFX_IDS_SCMOVE
AFX_IDS_SCNEXTWINDOW
AFX_IDS_SCPREVWINDOW
AFX_IDS_SCRESTORE
AFX_IDS_SCSIZE
AFX_IDS_SCTASKLIST
AFX_IDS_STATUS_FONT
AFX_IDS_TEXT_FORMAT
AFX_IDS_TOOLTIP_FONT
AFX_IDS_TWOPAGE
AFX_IDS_UNICODE_FONT
AFX_IDS_UNKNOWNTYPE
AFX_IDS_UNNAMED_FILE
AFX_IDS_UNTITLED
AFX_IDS_UPDATE_MENU
AFX_IDS_UPDATING_ITEMS
AFX_IDS_USER_EXCEPTION
AFX_IDS_VERB_EDIT
AFX_IDS_VERB_PROPERTIES
AFX_IDP_SQL_ILLEGAL_MODE
AFX_IDP_SQL_INCORRECT_ODBC
AFX_IDP_SQL_LOCK_MODE_NOT_SUPPORTED
AFX_IDP_SQL_MULTIPLE_ROWS_AFFECTED
AFX_IDP_SQL_NO_CURRENT_RECORD
AFX_IDP_SQL_NO_DATA_FOUND
AFX_IDP_SQL_NO_POSITIONED_UPDATES
AFX_IDP_SQL_NO_ROWS_AFFECTED
AFX_IDP_SQL_ODBC_LOAD_FAILED
AFX_IDP_SQL_ODBC_V2_REQUIRED
AFX_IDP_SQL_RECORDSET_FORWARD_ONLY
AFX_IDP_SQL_RECORDSET_READONLY
AFX_IDP_SQL_ROW_FETCH
AFX_IDP_SQL_ROW_UPDATE_NOT_SUPPORTED
AFX_IDP_SQL_SNAPSHOT_NOT_SUPPORTED
AFX_IDP_SQL_SQL_CONFORMANCE
AFX_IDP_SQL_SQL_NO_TOTAL
AFX_IDP_SQL_UPDATE_DELETE_FAILED
ID_FILE_MRU_FIRST
ID_FILE_MRU_LAST
ID_FILE_NEW_FRAME
ID_FILE_NEW
ID_FILE_OPEN
ID_FILE_PAGE_SETUP
ID_FILE_PRINT_DIRECT
ID_FILE_PRINT_PREVIEW
ID_FILE_PRINT_SETUP
ID_FILE_PRINT
ID_FILE_SAVE_AS
ID_FILE_SAVE_COPY_AS
ID_FILE_SAVE
ID_FILE_SEND_MAIL
ID_FILE_UPDATE
ID_FORMAT_FONT
ID_HELP_FINDER
ID_HELP_INDEX
ID_HELP_USING
ID_HELP
ID_INDICATOR_CAPS
ID_INDICATOR_EXT
ID_INDICATOR_KANA
ID_INDICATOR_NUM
ID_INDICATOR_OVR
ID_INDICATOR_REC
ID_INDICATOR_SCRL
ID_NEXT_PANE
ID_OLE_EDIT_CHANGE_ICON
ID_OLE_EDIT_CONVERT
ID_OLE_EDIT_LINKS
ID_OLE_EDIT_PROPERTIES
ID_OLE_INSERT_NEW
ID_OLE_VERB_FIRST
ID_PREV_PANE
ID_REC_FIRST
ID_RECORD_LAST
ID_RECORD_NEXT
ID_RECORD_PREV
ID_SEPARATOR
ID_VIEW_AUTOARRANGE
ID_VIEW_BYNAME
ID_VIEW_DETAILS
ID_VIEW_LARGEICON
ID_VIEW_LINEUP
ID_VIEW_LIST
ID_VIEW_REBAR
ID_VIEW_SMALLICON
ID_VIEW_STATUS_BAR
ID_VIEW_TOOLBAR
ID_WINDOW_ARRANGE
ID_WINDOW_CASCADE
ID_WINDOW_NEW
ID_WINDOW_SPLIT
ID_WINDOW_TILE_HORIZ
ID_WINDOW_TILE_VERT
ID_WIZBACK
ID_WIZFINISH
ID_WIZNEXT
IDABORT
IDC_STATIC
IDCANCEL
IDD_ABOUTBOX
IDIGNORE
IDNO
IDOK
IDP_OLE_INIT_FAILED
IDRETRY
IDYES
Requirements
MFC
See also
Predefined Symbol IDs
ATL Predefined Symbols
Win32 Predefined Symbols
Win32 Predefined Symbols
7/27/2022 • 2 minutes to read • Edit Online
These symbols are defined in the Win32 header files and they support standard Windows application functions
and actions. These symbols are mainly used with common UI elements. When you are working with controls in
the resource editors, these symbols will appear in the Properties window associated with common controls. For
instance, if your toolbar should display the application icon, the icon will be associated with the symbol
IDI_SMALL in the Proper ty window.
Requirements
Win32
See also
Predefined Symbol IDs
MFC Predefined Symbols
ATL Predefined Symbols
Resource Editors (C++)
7/27/2022 • 4 minutes to read • Edit Online
A resource editor is a specialized environment for creating or modifying resources that are included in a Visual
Studio project. The Visual Studio resource editors share techniques and interfaces to help you create and modify
application resources quickly and easily. Resource editors enable you to view and edit resources in the
appropriate editor and preview resources.
The appropriate editor opens automatically when you create or open a resource.
NOTE
Because managed projects do not use resource script files, you must open your resources from Solution Explorer . You
can use the Image Editor and the Binary Editor to work with resource files in managed projects. Any managed resources
you want to edit must be linked resources. The Visual Studio resource editors do not support editing embedded
resources.
USE T H E. . . TO EDIT. . .
Image Editor Bitmaps, icons, cursors, and other image files in Visual C++,
Visual Basic, or Visual C# projects.
Toolbar Editor Toolbar resources in Visual Studio C++ projects. The Toolbar
Editor is part of the Image Editor .
NOTE
If your project doesn't already contain an .rc file, see How to: Create Resources.
NOTE
Properties of a resource can be modified using the Proper ties window.
To edit the properties of a resource, in Resource View, right-click the resource you want to edit and
choose Proper ties . Then, in the Properties window, change the properties of your resource.
To undo a change made to the properties of a resource, make sure your resource has focus in Resource
View and choose Undo from the Edit menu.
Win32 Resources
You can access Win32 resources in the Resource View pane.
To view a Win32 resource in a resource editor
1. Go to menu View > Other Windows > Resource View .
2. If the Resource View window isn't the top-most window, select the Resource View tab to bring it to the
top.
3. From Resource View , expand the folder for the project that contains resources you want to view. For
example, if you want to view a dialog resource, expand the Dialog folder.
4. Double-click the resource, for example, IDD_ABOUTBOX .
The resource opens in the appropriate editor. For example, for dialog resources, the resource opens inside
the Dialog Editor .
To delete an existing Win32 resource
1. In Resource View , expand the node for a resource type.
2. Right-click on the resource you want to delete and choose Delete .
TIP
You can also use this method when you have the .rc file open in a document window outside a project.
NOTE
To preview resources requires Win32.
To preview resources
1. In Resource View or a document window, select your resource, for example, IDD_ABOUTBOX .
2. In the Properties window, select the Proper ty Pages button.
TIP
Use a shortcut, go to menu View > Proper ty Pages .
The Proper ty page for the resource opens displaying a preview of that resource. You can use the Up and
Down arrow keys to navigate the tree control in Resource View or the document window. The
Proper ty page will stay open and show any resource that has focus and can be previewed.
Requirements
None
See also
Working with Resource Files
Resource Files
Resource Identifiers (Symbols)
Accelerator Editor (C++)
7/27/2022 • 7 minutes to read • Edit Online
An accelerator table is a C++ Windows resource that contains a list of accelerator keys, known as shortcut keys,
and the command identifiers that are associated with them. A program can have more than one accelerator
table.
Normally, accelerators are used as keyboard shortcuts for program commands that are also available on a
menu or toolbar. However, you can use the accelerator table to define key combinations for commands that
don't have a user-interface object associated with them.
TIP
When using the Accelerator Editor , right-click to display a shortcut menu of frequent commands. The commands
available depend on what the pointer is pointing to.
You can use Class View to hook accelerator key commands to code. For a list of pre-defined accelerator keys, see
Accelerator Keys.
NOTE
Windows doesn't allow you to create empty accelerator tables. If you create an accelerator table with no entries, it is
deleted automatically when you save the table.
Accelerator Properties
You can set accelerator properties in the Properties window at any time. You can also use the Accelerator
Editor to modify the accelerator properties in the accelerator table. Changes made using the Proper ties
window or the Accelerator Editor have the same result, edits are immediately reflected in the accelerator
table.
The ID property references each accelerator table entry in program code. This entry is the command value that
the program receives when a user presses the accelerator key or a key combination. To make an accelerator the
same as a menu item, make the ID the same, so long as the ID of the accelerator table is the same as the ID for
the menu resource.
Each accelerator ID has three properties: Modifier , Key , and Type
The Modifier property sets control key combinations for the accelerator.
NOTE
In the Proper ties window, the Modifier property appears as three separate Boolean properties, all of which can be
controlled independently: Alt , Ctrl, and Shift .
The following are legal entries for the Modifier property in the accelerator table:
VA L UE DESC RIP T IO N
Ctrl User must press Ctrl before the Key value, not valid with
ASCII Type.
Ctrl+Alt User must press Ctrl and Alt before the Key value, not valid
with ASCII Type.
Ctrl+Shift User must press Ctrl and Shift before the Key value, not
valid with ASCII Type.
Alt+Shift User must press Alt and Shift before the Key value, not
valid with ASCII Type.
Ctrl+Alt+Shift User must press Ctrl, Alt , and Shift before the Key value,
not valid with ASCII Type.
The Key property sets the actual key to use as the accelerator.
The following are legal entries for the Key property in the accelerator table:
VA L UE DESC RIP T IO N
An integer between 0 and 255 in decimal format. The value determines whether the value is treated as ASCII
or ANSI as follows:
A single keyboard character in the range A - Z (uppercase This option enters the ASCII value of the key when it's
only), preceded by a caret (^), for example, ^C. pressed with the Ctrl key held down.
Any valid virtual key identifier. The drop-down Key box in the accelerator table contains a
list of standard virtual key identifiers.
NOTE
When entering an ASCII value, the Modifier property options are limited. The only control key available for use is the Alt
key.
TIP
A shortcut to define an accelerator key is to right-click an entry or multiple entries in the accelerator table, then choose
Next Key Typed and press any of the keys or key combinations on the keyboard.
This Next Key Typed command is also available from the Edit menu.
The Type property determines whether the shortcut key combination associated with the accelerator ID is
interpreted as an ASCII/ANSI key value or a virtual key (VIRTKEY) combination.
If the Type property is ASCII , the Modifier property may only be None or Alt , or it can have an
accelerator that uses the Ctrl key, as specified by preceding the key with a ^ .
If the Type property is VIRTKEY , any combination of Modifier and Key values is valid.
NOTE
If you want to enter a value into the accelerator table and have the value treated as ASCII/ANSI, select the Type for the
entry in the table and select ASCII from the dropdown list. However, if you use the Next Key Typed command from the
Edit menu to specify the Key , you must change the Type property from VIRTKEY to ASCII before entering the Key
code.
Accelerator Tables
In a C++ project, you can edit an accelerator table directly with in-place editing in the Accelerator Editor .
The procedures below refer to the use of standard property pages, however, both in-place editing and the
property page method have the same result. Changes made using property pages or using in-place editing are
immediately reflected in the accelerator table.
To edit in an accelerator table
1. Open the accelerator table by double-clicking its icon in Resource View.
2. Select an entry in the table and select to activate in-place editing.
3. Select from the drop-down combo box or type in place to make changes:
For ID , select from the list or type to edit.
For Modifier , select from the list.
For Key , select from the list or type to edit.
For Type , select ASCII or VIRTKEY from the list.
To find an entry in an open accelerator table
1. Open the accelerator table by double-clicking its icon in Resource View.
2. Select a column head to sort the contents of the column alphabetically. For example, select ID to display
all the IDs in your accelerator table alphabetically.
You can then scan the list and find the entry.
To add an entry to an accelerator table
1. Open the accelerator table by double-clicking its icon in Resource View.
2. Right-click within the accelerator table and choose New Accelerator , or select the empty row entry at
the bottom of the table.
3. Select an ID from the drop-down list in the ID box or type a new ID in the ID box.
4. Type the Key you want to use as an accelerator, or right-click and choose Next Key Typed to set a key
combination, or go to menu Edit > Next Key Typed .
5. Change the Modifier and Type , if necessary, and press Enter .
NOTE
Make sure all accelerators you define are unique. You can have several key combinations assigned to the same ID with no
ill effect, for example, Ctrl+P and F8 can both be assigned to ID_PRINT. However, having a key combination assigned to
more than one ID won't work well, for example, Ctrl+Z assigned to both ID_SPELL_CHECK and ID_THESAURUS.
TIP
You can also press the Delete key to delete.
NOTE
You can also use the shortcut keys for copying and pasting.
NOTE
Each modifier value appears as a Boolean property in the Proper ties window. If you change a modifier value in the
Proper ties window, the accelerator table treats the new modifier as an addition to any modifiers that were previously
there. Because of this, if you set any modifier values, you'll need to set all of them to ensure that every accelerator shares
the same Modifier settings.
Requirements
Win32
See also
Resource Editors
Accelerator Keys
Accelerator Keys (C++)
7/27/2022 • 2 minutes to read • Edit Online
K EY DESC RIP T IO N
VK_OEM_102 (Windows) Either the angle bracket key or the backslash key
on the RT 102-key keyboard
Requirements
Win32
See also
Accelerator Editor
Binary Editor (C++)
7/27/2022 • 4 minutes to read • Edit Online
Cau t i on
Editing resources such as dialog boxes, images, or menus in the Binar y Editor is dangerous. Incorrect editing
could corrupt the resource, making it unreadable in its native editor.
The Binar y Editor allows you to edit any resource at the binary level in either hexadecimal or ASCII format. You
can also use the Find command to search for either ASCII strings or hexadecimal bytes. Use the Binar y Editor
only when you need to view or make minor changes to custom resources or resource types not supported by
the Visual Studio environment. The Binar y Editor is not available in Express editions.
To open the Binar y Editor on a new file, go to menu File > New > File , select the type of file you want
to edit, then select the drop arrow next to the Open button, and choose Open With > Binar y Editor .
The dropdown selection in the New file dialog isn't available in Visual Studio 2019, but is available in
Visual Studio 2022.
To open the Binar y Editor on an existing file, go to menu File > Open > File , select the file you want to
edit, then select the drop arrow next to the Open button, and choose Open With > Binar y Editor .
TIP
While using the Binar y Editor , in many instances you can right-click to display a shortcut menu of resource-specific
commands. The commands available depend on what your cursor is pointing to. For example, if you right-click while
pointing to the Binar y Editor with selected hexadecimal values, the shortcut menu shows the Cut , Copy , and Paste
commands.
How To
The Binar y Editor enables you:
To open a Windows desktop resource for binary editing
1. In Resource View, select the specific resource file you want to edit.
2. Right-click the resource and select Open Binar y Data .
NOTE
If you use the Resource View window to open a resource with a format that Visual Studio doesn't recognize, such as
RCDATA or a custom resource, the resource is automatically opened in the Binar y Editor .
NOTE
You can use the Image Editor and the Binar y Editor to work with resource files in managed projects. Any managed
resources you want to edit must be linked resources. The Visual Studio resource editors do not support editing embedded
resources.
To edit a resource
If you want to use the Binar y Editor on a resource already being edited in another editor window, close the
other editor window first.
1. Select the byte you want to edit.
The Tab key moves the focus between the hexadecimal and ASCII sections of the Binar y Editor . You can
use the Page Up and Page Down keys to move through the resource one screen at a time.
2. Type the new value.
The value changes immediately in both the hexadecimal and ASCII sections and focus shifts to the next
value in line.
NOTE
The Binar y Editor accepts changes automatically when you close the editor.
#include mydata.rc
Make sure the syntax and spelling of what you type are correct. The contents of the Compile-Time
Directives box are inserted into the resource script file exactly as you type them.
4. Select OK to record your changes.
Another way to create a custom resource is to import an external file as the custom resource, see How to:
Manage Resources.
NOTE
Creating new custom or data resources requires Win32.
Requirements
None
See also
Resource Editors
Dialog Editor (C++)
7/27/2022 • 4 minutes to read • Edit Online
The Dialog Editor allows you to create or edit dialog box resources.
To open the editor, double-click on a dialog's .rc file in the Resource View window, or go to menu View >
Other Windows > Resource View .
One of the first steps in making a new dialog box or dialog box template, is adding controls. In the Dialog
Editor , you can arrange controls to fit a certain size, shape, or alignment, or you can move them around to work
within the dialog box. It's also easy to delete a control.
You can store a dialog box as a template so you can reuse it. You can also easily switch between designing the
dialog box and editing the code that implements it.
It's also possible to edit properties of single or multiple controls in the Dialog Editor . You can change the tab
order, that is, the order in which controls gain focus when the Tab key is pressed, or you can define an access
key or key combination that allows users to choose a control using the keyboard.
The Dialog Editor also allows you to use custom controls, including ActiveX controls. You can also edit a form
view, record views, or dialog bars.
Starting with Visual Studio 2015, you can use the Dialog Editor to define dynamic layouts, which specify how
controls move and resize when the user resizes a dialog. For more information, see Dynamic Layout.
For more information on resources, see how to Create a Dialog Box and Dialog Box Controls.
TIP
While using the Dialog Editor , in many instances, you can select with the right mouse button to display a shortcut
menu of frequently used commands.
IC O N M EA N IN G IC O N M EA N IN G
To show or hide the Dialog Editor toolbar, go to menu View > Toolbars > Dialog Editor .
When you open the Dialog Editor in a C++ project, the Dialog Editor toolbar automatically appears at the
top of your solution, however, if you explicitly close the toolbar, you'll need to invoke it the next time you open
the Dialog Editor . You can toggle its display by selecting it from the list of available toolbars and windows.
NOTE
Choosing the ControlEvents button when the dialog box has focus exposes a list of all the controls in the dialog
box, which you can then expand to edit the events for the individual controls.
To view messages for a dialog box, with the dialog box selected, choose the Messages button in the
Proper ties window.
Accelerator Keys
Below are the default accelerator keys for the Dialog Editor commands.
Format.AlignBottoms Ctrl + Shift + Down Arrow Aligns the bottom edges of the
selected controls with the dominant
control.
Format.AlignLefts Ctrl + Shift + Left Arrow Aligns the left edges of the selected
controls with the dominant control.
Format.AlignRights Ctrl + Shift + Right Arrow Aligns the right edges of the selected
controls with the dominant control.
Format.AlignTops Ctrl + Shift + Up Arrow Aligns the top edges of the selected
controls with the dominant control.
To change shortcut keys, go to menu Tools > Options , and choose Keyboard under the Environment
folder.
For more information, see Identifying and Customizing Keyboard Shortcuts.
To change your settings, go to menu Tools > Impor t and Expor t Settings .
The options available in dialog boxes, and the names and locations of menu commands you see, might
differ from what is described in Help depending on your active settings or edition. For more information,
see Personalize the Visual Studio IDE.
Requirements
Win32
See also
Resource Editors
How to: Create a Dialog Box
Dialog Box Controls
How to: Create a Dialog Box (C++)
7/27/2022 • 3 minutes to read • Edit Online
The location and size of a C++ dialog box, and the location and size of controls within it, are measured in dialog
units. The values for individual controls and the dialog box appear in the lower right of the Visual Studio status
bar when you select them.
NOTE
If your project doesn't already contain an .rc file, see Creating a New Resource Script File.
How To
The Dialog Editor enables you:
To create a new dialog box
1. In Resource View, right-click your .rc file and select Add Resource .
2. In the Add Resource dialog box, select Dialog in the Resource Type list, then choose New .
If a plus sign (+ ) appears next to the Dialog resource type, it means that dialog box templates are
available. Select the plus sign to expand the list of templates, select a template, and choose New .
The new dialog box opens in the Dialog Editor .
You can also open existing dialog boxes in the Dialog Box editor for editing.
To create a dialog box that a user can't exit
You can create a runtime dialog box that a user can't exit. This kind of dialog box is useful for logons, and for
application or document locks.
1. In the Proper ties pane for the dialog box, set the System Menu property to false .
This setting disables the dialog box system menu and Close button.
2. In the dialog box form, delete the Cancel and OK buttons.
At run time, a user can't exit a modal dialog box that has these characteristics.
To enable testing of this kind of dialog box, the test dialog box function detects when Esc is pressed. Esc is also
known as the VK_ESCAPE virtual key. No matter how the dialog box is designed to behave at run time, you can
end test mode by pressing Esc .
NOTE
For MFC applications, to create a dialog box that users cannot exit, you must override the default behavior of OnOK and
OnCancel because even if you delete the associated buttons, the dialog box can still be dismissed by pressing Enter or
Esc.
NOTE
Connections to dialog box code made by using wizards aren't included in the simulation.
When you test a dialog box, it typically displays at a location that's relative to the main program window. If
you've set the dialog box Absolute Align property to True , the dialog box displays at a position that's relative
to the upper-left corner of the screen.
1. When the Dialog Editor is the active window, go to menu Format > Test Dialog .
2. To end the simulation, press Esc or select the Close button in the dialog box you're testing.
Requirements
Win32
See also
Dialog Editor
How to: Manage Dialog Box Controls
Dialog Box Controls (C++)
7/27/2022 • 3 minutes to read • Edit Online
You can add controls to a dialog box using the Dialog Editor tab in the Toolbox window that enables you to
choose the control you want and drag it onto the dialog box. By default, the Toolbox window is set to auto hide.
It appears as a tab on the left margin of your solution when the Dialog Editor is open. However, you can pin
the Toolbox window into position by selecting the Auto Hide button in the upper right corner of the window.
For more information on how to control the behavior of this window, see Window Management.
The fastest way to add controls to a dialog box, reposition existing controls, or move controls from one dialog
box to another, is to use the drag-and-drop method. The control's position is outlined in a dotted line until it is
dropped into the dialog box. When you add a control to a dialog box with the drag-and-drop method, the
control is given a standard height appropriate to that type of control.
When you add a control to a dialog box or reposition it, its final placement may be determined by guides or
margins, or whether you have the layout grid turned on.
Once you have added a control to the dialog box, you can change properties such as its caption in the Properties
Window. You can also select multiple controls and change their properties all at once.
For more information on the Dialog Editor , see how to Add, Edit, or Delete Controls, Layout Controls, and
Define Control Access and Values.
For more information on controls and dialogs, see Control Classes, Dialog Box Classes, and Scroll-Bar Styles.
The standard controls available in the Toolbox with default events are:
The Windows Common Controls available in the Toolbox to provide increased functionality are:
Custom Controls
The Dialog Editor lets you use existing custom or user controls in a dialog box template.
NOTE
Custom controls in this sense are not to be confused with ActiveX controls. ActiveX controls were sometimes called OLE
custom controls. Also, don't confuse these controls with the owner-drawn controls in Windows.
This functionality is intended to let you use controls other than those supplied by Windows. At run time, the
control is associated with a Window class (not the same as a C++ class). A more common way to accomplish the
same task is to install any control, such as a static control, in your dialog box. Then at run time, in the
OnInitDialog function, remove that control and replace it with your own custom control.
NOTE
This is an old technique. Today you are advised in most cases to write an ActiveX control or subclass a Windows common
control.
Requirements
Win32
See also
Dialog Editor
How To: Add, Edit, or Delete Controls (C++)
7/27/2022 • 7 minutes to read • Edit Online
Using the Dialog Editor , you can add, resize, edit, and delete controls in dialog boxes. You can also edit the
properties of a control, such as its ID, or whether it's initially visible at run time.
The Dialog Editor tab appears in the Toolbox window when you're working in the Dialog Editor . You can also
customize the Toolbox window for easier use. For more information, see Using the Toolbox and Show or hide
the Toolbox window.
TIP
While using the Dialog Editor , in many instances, you can select the right mouse button to display a shortcut menu of
frequently used commands.
Add Controls
To add a control
1. Ensure that the dialog box tabbed window is the current document in the editor frame. If a dialog isn't the
current document, you won't see the Dialog Editor Tab in the Toolbox .
2. On the Dialog Editor tab of the Toolbox window, select the control you want, then either:
Select the dialog box at the location where you want to place the control and the control appears
where you've selected.
Drag and drop the control from the Toolbox window to the location on your dialog box. You can
then move the control around, or change its size and shape.
Double-click the control in the Toolbox window and it appears on your dialog box. Reposition the
control to the location you prefer.
To add multiple controls
1. While holding down the Ctrl key, select a control in the Toolbox window.
2. Release the Ctrl key and select the dialog box as many times as you want to add the particular control.
3. Press Esc to stop placing controls.
To size a control while you add it
1. Select a control in the Toolbox window.
2. Place your cursor that appears as cross hairs, where you want the upper-left corner of the new control to
be on your dialog box.
3. Select and hold down the mouse button to anchor the upper-left corner of your control on the dialog box.
Then drag the cursor to the right and down, until the control is the size you want.
NOTE
You can anchor any of the four corners of the control you're drawing. This procedure used the upper-left corner as
an example.
4. Release the mouse button. The control settles onto the dialog box in the size you specified.
TIP
You can resize the control after dropping it onto the dialog box by moving the sizing handles on the border of the control.
For more information, see Sizing Individual Controls.
Edit Controls
To edit the properties of a control or controls
1. In the dialog box, select the control you want to modify.
NOTE
If you select multiple controls, only the properties common to the selected controls can be edited.
NOTE
When you set the Bitmap property for a button, radio button, or check box control equal to True , the style
BS_BITMAP is implemented for your control. For more information, see Button Styles. For an example of
associating a bitmap with a control, see CButton::SetBitmap. Bitmaps will not appear on your control while you are
in the Dialog Editor .
NOTE
This process applies only to dialog controls within an MFC project. ATL projects should use the New Windows
Messages and Event Handlers dialog box. For more information, see Message Types Associated with User-Interface
Objects, Editing a Message Handler, and Defining a Message Handler for a Reflected Message.
You can also use the Member Variables tab in the MFC Class Wizard to add new member variables for a
specified class, and view already-defined member variables.
Delete Controls
In the dialog box, select the control, then press the Delete key, or go to menu Edit > Delete .
Other Issues
Troubleshooting
After you add a common control or rich edit control to a dialog box, it won't appear when you test the dialog
box. Or, the dialog itself won't appear. For example:
1. Create a Win32 project, modifying the application settings so you create a Windows application (not a
console app).
2. In Resource View, double-click on the .rc file.
3. Under the dialog option, double-click the About box.
4. Add an IP Address Control to the dialog box.
5. Save and Rebuild all .
6. Execute the program.
7. On the dialog box's Help menu, select the About command and observe no dialog box is displayed.
Currently, the Dialog Editor doesn't automatically add code to your project when you drag and drop the
following common controls or rich edit controls onto a dialog box. Nor does Visual Studio provide an error or
warning when this problem occurs. To fix, add the code for the control manually.
Animation Control
Custom Control
Date Time Picker
Extended Combo Box
Hot Key
IP Address Control
List Control
Month Calendar
Progress Control
Rich Edit 2.0 Control
Rich Edit Control
Slider Control
Spin Control
Tab Control
Tree Control
To use common controls on a dialog box, you need to call InitCommonControlsEx or AFXInitCommonControls
before you create the dialog box.
To use RichEdit controls, you must call LoadLibrary . For more information, see About Rich Edit Controls in the
Windows SDK and Overview of the Rich Edit Control.
NOTE
To use a RichEdit control with MFC, you must first call AfxInitRichEdit2 to load the RichEdit 2.0 Control (RICHED20.DLL), or
call AfxInitRichEdit to load the older RichEdit 1.0 Control (RICHED32.DLL).
You may use the current CRichEditCtrl class with the older RichEdit 1.0 control, but CRichEditCtrl is only designed to
support the RichEdit 2.0 control. Because RichEdit 1.0 and RichEdit 2.0 are similar, most methods will work. However,
there are some differences between the 1.0 and 2.0 controls, so some methods might work incorrectly or not work at all.
Cau t i on
It may not be legal to distribute all of the ActiveX controls on your system. Refer to the license agreement for the
software that installed the controls or contact the software company.
To add an ActiveX control
1. Open a dialog box in the Dialog Editor .
2. Right-click anywhere in the body of the dialog box and select Inser t ActiveX Control .
The Inser t ActiveX Control dialog box appears, showing all the ActiveX controls on your system. At the
bottom of the dialog box, the path to the ActiveX Control file appears.
3. Select the control you want to add to your dialog box and choose OK .
The control appears in the dialog box, where you can edit it or create handlers for it just as you would any
other control.
TIP
You can use the shortcut menu in the Dialog Editor to quickly add registered ActiveX controls to a dialog box, or try
adding ActiveX controls to the Toolbox window for easy access.
NOTE
This procedure applies to using the property page to edit ActiveX controls. You can also browse and edit ActiveX
properties in the new Proper ties window.
Requirements
Win32
See also
Manage Dialog Box Controls
How To: Layout Controls
How to: Define Control Access and Values
How To: Layout Controls (C++)
7/27/2022 • 10 minutes to read • Edit Online
The Dialog Editor provides layout tools that align and size controls automatically. For most tasks, you can use
the Dialog Editor toolbar. All Dialog Editor toolbar commands are also available on the Format menu, and
most have shortcut keys.
Many layout commands for dialog boxes are available only when more than one control is selected. You can
select a single control or multiple controls, and when more than one control is selected, the first one you select
is by default the dominant control.
The location, height, and width of the current control are displayed in the lower-right corner of the status bar.
When the entire dialog box is selected, the status bar displays the position of the dialog box as a whole, and its
height and width.
Arrange Controls
You can arrange controls on dialog boxes with the Dialog Editor in one of three different states:
With guides and margins on, set as default.
With the layout grid on.
Without any snap or alignment features.
The Dialog Editor toolbar contains buttons that control the state.
To change the state, select the appropriate icon, or go to menu Format > Guide Settings .
The Guide Settings dialog box has the following properties:
Rulers and guides When enabled, adds rulers to the layout tools and allows
guides to be placed in the rulers. The default guides are the
margins.
Grid spacing Displays the settings for the grid spacing in dialog box units
(DLUs).
Width: DLUs Sets the width of the layout grid in DLUs. A horizontal DLU
is the average width of the dialog box font divided by 4.
Height: DLUs Sets the height of the layout grid in DLUs. A vertical DLU is
the average height of the dialog box font divided by 8.
TIP
You can also use the shortcut in the menu Format > Toggle Guides .
Select Controls
Select controls to size, align, move, copy, or delete them, and then complete the operation you want. In most
cases, you need to select more than one control to use the sizing and alignment tools on the Dialog Editor
toolbar.
When a control is selected, it has a shaded border around it with solid (active) or hollow (inactive) sizing
handles, small squares that appear in the selection border. When multiple controls are selected, the dominant
control has solid sizing handles and all the other selected controls have hollow sizing handles.
To select controls, in the Toolbox Window, select the Pointer tool and use one of the following steps to
make your selection:
Drag the pointer to draw a selection box around the controls you want to select in your dialog box.
When you release the mouse button, all controls inside and intersecting the selection box are
selected.
Hold down the Shift key and select the controls you'd like to include in the selection.
Hold down the Ctrl key and select the controls you'd like to include in the selection.
To add or remove a control from the group of selected controls, hold down the Shift key and select the
control you want to add or remove.
Dominant Controls
When you're sizing or aligning multiple controls, the Dialog Editor uses the dominant control to determine
how the other controls are sized or aligned. By default, the dominant control is the first control selected.
To specify the dominant control, hold down the Ctrl key and select the control you want to use to
influence the size or location of other controls first. Holding down the Ctrl key and selecting a control
within a selection will also make that control the dominant control in that selection.
To change the dominant control, clear the current selection by selecting outside all the currently selected
controls and repeat the above procedure, selecting a different control first.
NOTE
The sizing handles of the dominant control are solid while the handles of subordinate controls are hollow. All further
resizing or alignment is based on the dominant control.
Size Controls
Use the sizing handles to resize a control. When the pointer is positioned on a sizing handle, it changes shape to
indicate the directions in which the control can be resized. Active sizing handles are solid and if a sizing handle is
hollow, the control can't be resized along that axis.
To size a control, select the control and drag the sizing handles to change the size.
Size handles at the top and sides change the horizontal or vertical size.
Size handles at the corners change both horizontal and vertical size.
TIP
You can resize the control one dialog unit (DLU) at a time by holding down the Shift key and using the Right and
Down arrow keys.
To automatically size a control to fit the text within it, go to menu Format or right-click the control, and
choose Size to Content .
To make controls the same size, select the controls you want to resize and go to menu Format > Make
Same Size , then choose either Both , Height , or Width .
You resize a group of controls based on the size of the dominant control, which is the control selected
first in the series. The final size of the controls in the group depends on the size of the dominant control.
To size a group of controls with guides, snap one side of the control (or controls) to a guide, then drag a
guide to the other side of the control (or controls). Now you can move either guide to size the control (or
controls).
If necessary with multiple controls, size each to snap to the second guide.
Other Controls
You can size a combo box when you add it to the dialog box. You can also specify the size of the drop-down list
box. For more information, see Adding Values to a Combo Box Control.
1. Select the drop-down arrow button at the right of the combo box.
The outline of the control changes to show the size of the combo box with the drop-down list area
extended.
2. Use the lower sizing handle to change the initial size of the drop-down list area.
3. Select the drop-down arrow again to close the drop-down list portion of the combo box.
NOTE
When you add a list box with a horizontal scroll bar to a dialog box using MFC, the scroll bar won't automatically appear
in your application.
Set a maximum width for the widest element by calling CListBox::SetHorizontalExtent in your code. Without this value set,
the scroll bar won't appear, even when the items in the list box are wider than the box.
Align Controls
To align controls, select the controls you want to align. Go to menu Format > Align and choose one of
the following alignments:
A L IGN M EN T DESC RIP T IO N
Be sure to select the control that you want to be dominant first or set it to be the dominant control before
executing the alignment or sizing command as the final position of the group of controls depends on the
position of the dominant control.
To evenly space controls, select the controls you want to rearrange. Go to menu Format > Space Evenly
and choose one of the following spacing alignments:
To center controls, select the control or controls you want to rearrange. Go to menu Format > Center In
Dialog and choose one of the following arrangements:
To align push buttons, select one or more push buttons. Go to menu Format > Arrange Buttons , then
choose one of the following arrangements:
Right Aligns push buttons along the right edge of the dialog
box.
If you select a control other than a push button, its position isn't affected.
Requirements
Win32
See also
Manage Dialog Box Controls
How To: Add, Edit, or Delete Controls
How to: Define Control Access and Values
How to: Define Control Access and Values (C++)
7/27/2022 • 6 minutes to read • Edit Online
Tab Order
The tab order is the order in which the Tab key moves the input focus from one control to the next within a
dialog box. Usually the tab order proceeds from left to right and from top to bottom in a dialog box. Each control
has a Tabstop property that determines whether a control receives input focus.
To set input focus for a control, in the Properties Window, select True or False in the Tabstop property.
Even controls that don't have the Tabstop property set to True need to be part of the tab order, especially for
controls that don't have captions. Static text that contains an access key for a related control must immediately
precede the related control in the tab order.
NOTE
If your dialog box contains overlapping controls, changing the tab order may change the way the controls are displayed.
Controls that come later in the tab order are always displayed on top of any overlapping controls that precede them in
the tab order.
To view the current tab order for all controls, go to menu Format > Tab Order , or press Ctrl + D .
A number in the upper-left corner of each control shows its place in the current tab order.
To change the tab order for all controls, go to menu Format > Tab Order and set the tab order by
selecting each control in the order you want the Tab key to follow.
To change the tab order for two or more controls, go to menu Format > Tab Order . Hold down the Ctrl
key and select the control where the change in order will begin, then release the Ctrl key and select the
controls in the order you want the Tab key to follow from that point.
For example, if you want to change the order of controls 7 through 9 , hold down Ctrl , then select
control 6 first.
To set a specific control to number 1 , or first in the tab order, double-click the control.
TIP
Once you enter Tab Order mode, press Esc or Enter to exit Tab Order mode and disable the ability to change the tab
order.
NOTE
All access keys within a dialog box should be unique. To check for duplicate access keys, go to menu Format > Check
Mnemonics .
TIP
It's a good idea to add all values to the combo box before you size the box in the Dialog Editor , or you may truncate
text that should appear in the combo control.
NOTE
If you're displaying properties grouped by type, Data appears in the Misc properties.
3. Select the value area for the Data property and type in your data values, separated by semicolons.
NOTE
Don't put spaces between values because spaces interfere with alphabetizing in the drop-down list.
NOTE
You can't add values to Win32 projects using this procedure (the Data property is grayed out for Win32 projects).
Because Win32 projects do not have libraries that add this capability, you must add values to a combo box with a Win32
project programmatically.
NOTE
Only the first radio button in the group should have the Group property set to True . If you have additional
controls that aren't part of the button group, set the Group property of the first control that is outside the group
to True as well. You can quickly identify the first control outside of the group by using Ctrl+D to view the tab
order.
Requirements
Win32
See also
Manage Dialog Box Controls
How To: Add, Edit, or Delete Controls
How To: Layout Controls
Image Editor for Icons (C++)
7/27/2022 • 9 minutes to read • Edit Online
When you select an image file (such as .ico, .bmp, .png) in Solution Explorer , the image opens in the Image
Editor in the same way that code files open in the Code Editor . When an Image Editor tab is active, you see
toolbars with many tools for creating and editing images. Along with bitmaps, icons, and cursors, you can edit
images in GIF or JPEG format using commands on the Image menu and tools on the Image Editor toolbar.
Graphical resources are the images you define for your application. You can draw freehand or draw using
shapes. You can select parts of an image for editing, flipping or resizing, or you can create a custom brush from
a selected part of an image and draw with that brush. You can define image properties, save images in different
formats, and convert images from one format to another.
NOTE
Using the Image Editor , you can view 32-bit images, but you can't edit them.
You can also use the Image Editor and the Binary Editor to work with resource files in managed projects. Any
managed resources you want to edit must be linked resources. The Visual Studio resource editors don't support
editing embedded resources.
In addition to creating new graphical resources, you can import existing images for editing and then add them
to your project. You can also open and edit images that are not part of a project for stand-alone image editing.
For information on the Image Editor , see how to Create an Icon or Other Image, Edit an Image, Use a Drawing
Tool, Work with Color, and Accelerator Keys.
NOTE
Download at no cost the Visual Studio Image Librar y that contains many animations, bitmaps, and icons that you can
use in your applications. For more information about how to download the library, see the Visual Studio Image Library.
Image Menu
The Image menu, which appears only when the Image Editor is active, has commands for editing images,
managing color palettes, and setting Image Editor window options. Also, commands for using device images
are available when working with icons and cursors.
Show Colors Window Opens the Colors window, in which you can choose the
colors to use for your image.
Use Selection as Brush Enables you to create a custom brush from a portion of an
image.
Copy and Outline Selection Creates a copy of the current selection and outlines it.
Adjust Colors Opens the Custom Color Selector , which allows you to
customize the colors you use for your image.
Load Palette Opens the Load Color Palette dialog box, which enables
you to load palette colors previously saved to a .pal file.
Grid Settings Opens the Grid Settings dialog box in which you can
specify grids for your image.
New Image Type Opens the New <Device> Image Type dialog box.
Current Icon/Cursor Image Type Opens a submenu that lists the first nine available cursor or
icon images. The last command on the submenu, More ,
opens the Open <Device> Image dialog box.
The Grid Settings dialog box allows you to specify the grid settings for your image and displays grid lines over
the edited image. The lines are useful for editing the image, but aren't saved as part of the image itself.
P RO P ERT Y DESC RIP T IO N
Pixel grid When checked, displays a grid around each pixel in the
Image Editor .
Tile grid When selected, displays a grid around blocks of pixels in the
Image Editor , specified by the grid spacing values.
Toolbar
The Image Editor toolbar contains tools for drawing, painting, entering text, erasing, and manipulating views. It
also contains an option selector, with which you can select options for using each tool. For example, you can
choose from various brush widths, magnification factors, and line styles.
All tools available on the Image Editor toolbar are also available from the menu Image > Tools . To use the
Image Editor toolbar and Option selector, select the tool or option that you want.
TIP
Tool tips appear when you hover your cursor over a toolbar button. These tips can help you identify the function of each
button.
Since many of the drawing tools are available from the keyboard, it's sometimes useful to hide the Image
Editor toolbar.
To display or hide the Image Editor toolbar, go to menu View > Toolbars and choose Image Editor .
NOTE
Elements from this toolbar will appear unavailable when an image file from the current project or solution isn't open in the
Image Editor .
Option selector
With the Option selector you can specify the width of a line, brush stroke, and more. The icon on the Option
selector button changes depending on which tool you've selected.
TIP
You can right-click on the Text Tool dialog box to access a default shortcut menu that contains a list of standard
Windows commands.
Open the Text Tool Font dialog box to change the font, style, or size of the cursor font. Changes are applied to
the text displayed in the Text area.
To access this dialog box, select the Font button in the Text Tool dialog box. The properties available are:
Font Style Lists the available styles for the specified font.
Size Lists the available point sizes for the specified font.
Sample Shows a sample of how text will appear with the specified
font settings.
Script Lists the available language scripts for the specified font.
NOTE
If Transparent Background is set, only the text will be placed into the image. If Opaque Background is set, a
bounding rectangle, filled with the background color, will be placed behind the text.
Window Panes
The Image Editor window shows two views of an image, with a split bar separating the two panes. You can
drag the split bar from side to side to change the relative sizes of the panes. The active pane displays a selection
border.
One view is actual size and the other is enlarged by a default enlargement factor of 6. The views in these two
panes are updated automatically, any changes you make in one pane are immediately shown in the other. The
two panes make it easy for you to work on an enlarged view of your image, in which you can distinguish
individual pixels and, at the same time, observe the effect of your work on the actual-size view of the image.
The left pane uses as much space as is needed (up to half of the Image window) to display the default 1:1
magnification view of your image. The right pane displays a default 6:1 magnification zoomed image. You can
change the magnification in each pane using the Magnify tool on the Image Editor toolbar or by using the
accelerator keys.
You can enlarge the smaller pane of the Image Editor window and use the two panes to show different regions
of a large image. Select inside the pane to choose it.
You can change the relative sizes of the panes by positioning the pointer on the split bar and moving the split
bar to the right or left. The split bar can move all the way to either side if you want to work on only one pane.
If the Image Editor pane is enlarged by a factor of 4 or greater, you can display a pixel grid that delimits the
individual pixels in the image.
To change the magnification factor
By default, the Image Editor displays the view in the left pane at actual size and the view in the right pane at 6
times actual size. The magnification factor (seen in the status bar at the bottom of the workspace) is the ratio
between the actual size of the image and the displayed size. The default factor is 6 and the range is from 1 to 10.
1. Select the Image Editor pane whose magnification factor you want to change.
2. On the Image Editor toolbar, select the arrow to the right of the Magnify tool and select the
magnification-factor from the submenu: 1X , 2X , 6X , or 8X .
NOTE
To select a magnification factor other than those listed in the Magnify tool, use the accelerator keys.
Requirements
None
See also
Resource Editors
Icons
How To: Create an Icon or Other Image
7/27/2022 • 10 minutes to read • Edit Online
You can create a new image, bitmap, icon, cursor, or toolbar, and then use the Image Editor to customize its
appearance. You can also create a new bitmap patterned after a resource template.
Monochrome 16 16
Monochrome 32 32
Monochrome 48 48
Monochrome 64 64
Monochrome 96 96
16 16 16
16 32 32
16 64 64
16 48 48
16 96 96
256 16 16
256 32 32
256 48 48
256 64 64
C O LO R W IDT H ( P IXEL S) H EIGH T ( P IXEL S)
256 96 96
NOTE
If your project doesn't already contain an .rc file, see Creating a New Resource Script File.
The New <Device> Image Type dialog box enables you to create a new device image of a specified type. To
open the New <Device> Image dialog box, go to menu Image > New Image Type . The following properties
included are Target Image Type and Custom .
The Target Image Type property lists the available image types where you select the image type you want to
open:
16 x 16, 16 colors
32 x 32, 16 colors
48 x 48, 16 colors
64 x 64, 16 colors
96 x 96, 16 colors
16 x 16, 256 colors
32 x 32, 256 colors
48 x 48, 256 colors
64 x 64, 256 colors
96 x 96, 256 colors
16 x 16, Monochrome
32 x 32, Monochrome
48 x 48, Monochrome
64 x 64, Monochrome
96 x 96, Monochrome
NOTE
Any existing images will not be displayed in this list.
The Custom property opens the Custom Image dialog box in which you can create a new image with a
custom size and number of colors.
The Custom Image dialog box enables you to create a new image with a custom size and number of colors.
The following properties included are:
P RO P ERT Y DESC RIP T IO N
Width Provides a space for you to enter the width of the custom
image in pixels (1 - 512, limit of 2048).
Height Provides a space for you to enter the height for the custom
image in pixels (1 - 512, limit of 2048).
Colors Provides a space for you to choose the number of colors for
the custom image: 2, 16, or 256.
Use the Open <Device> Image dialog box to open device images in C++ projects. It lists existing device
images in the current resource (images that are part of the current resource). The following property included is:
Current Images Lists the images included in the resource. Select the image
type you want to open.
NOTE
The dialog boxes and menu commands you see might differ from those described in Help depending on your active
settings or edition. To change your settings, go to menu Tools > Impor t and Expor t Settings . For more information,
see Personalize the Visual Studio IDE.
TIP
If you double-click the Screen-Color or Inverse-Color selector, the Custom Color Selector dialog box appears.
NOTE
The initial palette used for 256-color images matches the palette returned by the CreateHalftonePalette
Windows API. All icons intended for the Windows shell should use this palette to prevent flicker during palette
realization.
NOTE
This process doesn't apply to icons and cursors.
NOTE
You must create or open the bitmap outside of your project in order to save it as another file format. If you create
or open it within your project, the Save As command will be unavailable. For more information, see Viewing
Resources in a Resource Script File Outside of a Project (Standalone).
6. Select Save .
To convert an image from one format to another
You can open GIF or JPEG images in the Image Editor and save them as bitmaps. Also, you can open a bitmap
file and save it as a GIF or JPEG. Images you work with need not be part of a project for editing in the
development environment (see stand-alone image editing).
1. Open the image in the Image Editor .
2. Go to menu File > Save filename As .
3. In the Save File As dialog box, in the File name box, type the file name and the extension that denotes
the format you want.
4. Select Save .
To add a new image resource to an unmanaged C++ project
1. In Resource View, right-click your .rc file, then choose Inser t Resource . If you already have an existing
image resource in your .rc file, such as a cursor, you can simply right-click the Cursor folder and select
Inser t Cursor .
2. In the Insert Resource dialog box, select the type of image resource you'd like to create (Bitmap , for
example) then choose New .
If a plus sign (+ ) appears next to the image resource type in the Inser t Resource dialog box, it means
that toolbar templates are available. Select the plus sign to expand the list of templates, select a template,
and choose New .
To add a new image resource to a project in a .NET programming language
1. In Solution Explorer , right-click the project folder (for example, WindowsApplication1).
2. From the shortcut menu, select Add , then choose Add New Item .
3. In the Categories pane, expand the Local Project Items folder, then choose Resources .
4. In the Templates pane, choose the resource type you'd like to add to your project.
The resource is added to your project in Solution Explorer and the resource opens in the Image Editor.
You can now use all the tools available in the Image Editor to modify your image. For more information
on adding images to a managed project, see Loading a Picture at Design Time.
Requirements
None
See also
Image Editor for Icons
How to: Edit an Image
How to: Use a Drawing Tool
How to: Work with Color
Accelerator Keys
How to: Edit an Image
7/27/2022 • 8 minutes to read • Edit Online
You can use selection tools to define an area of an image that you want to cut, copy, clear, resize, invert, or move.
With the Rectangle Selection tool you can define and select a rectangular region of the image. With the
Irregular Selection tool you can draw a freehand outline of the area you want to select for the cut, copy, or
other operation.
NOTE
See the Rectangle Selection and Irregular Selection tools pictured in Image Editor toolbar or view the tool tips
associated with each button on the Image Editor toolbar.
You can also create a custom brush from a selection. For more information, see Creating a Custom Brush.
How To
To edit an image, see how:
To select an image
1. Use the Image Editor toolbar or go to menu Image > Tools and choose the selection tool you want.
2. Move the insertion point to one corner of the image area that you want to select. Cross hairs appear
when the insertion point is over the image.
3. Drag the insertion point to the opposite corner of the area you want to select. A rectangle shows which
pixels will be selected. All pixels within the rectangle, including those under the rectangle, are included in
the selection.
4. Release the mouse button. The selection border encloses the selected area.
To select an entire image
Select the image outside of the current selection. The selection border changes focus and encompasses the
whole image once again.
To edit parts of an image
You can perform standard editing operations — cutting, copying, clearing, and moving — on a selection,
whether the selection is the entire image or just a part of it. Because the Image Editor uses the Windows
Clipboard , you can transfer images between the Image Editor and other applications for Windows.
In addition, you can resize the selection, whether it includes the entire image or just a part.
To cut the current selection and move it to the clipboard
Go to menu Edit > Cut .
To copy the selection
1. Position the pointer inside the selection border or anywhere on it except the sizing handles.
2. Hold down the Ctrl key as you drag the selection to a new location. The area of the original selection is
unchanged.
3. To copy the selection into the image at its current location, select outside the selection cursor.
To paste the clipboard contents into an image
1. Go to menu Edit > Paste .
The clipboard contents, surrounded by the selection border, appear in the upper-left corner of the pane.
2. Position the pointer within the selection border and drag the image to the desired location on the image.
3. To anchor the image at its new location, select outside of the selection border.
To delete the current selection without moving it to the clipboard
Go to menu Edit > Delete .
The original area of the selection is filled with the current background color.
NOTE
You can access the Cut , Copy , Paste , and Delete commands by right-clicking in the Resource View window.
NOTE
You can also use the accelerator (shortcut) keys for these commands or access the commands from the shortcut
menu (select outside the image while in the Image Editor ).
To resize an image
The behavior of the Image Editor while resizing an image depends on whether you've selected the entire
image or just part of it.
When the selection includes only part of the image, the Image Editor shrinks the selection by deleting rows or
columns of pixels and filling the vacated regions with the current background color. It can also stretch the
selection by duplicating rows or columns of pixels.
When the selection includes the entire image, the Image Editor either shrinks and stretches the image, or crops
and extends it.
There are two mechanisms for resizing an image: the sizing handles and the Properties window. You drag the
sizing handles to change the size of all or part of an image. Sizing handles that you can drag are solid. You can't
drag handles that are hollow. Use the Proper ties window to resize the entire image only, not a selected part.
Sizing handles
NOTE
If you have the Tile Grid option selected in the Grid Settings dialog box, then resizing snaps to the next tile grid line. If
only the Pixel Grid option is selected (the default setting), resizing snaps to the next available pixel.
NOTE
You can use the Width and Height properties to resize only the entire image, not to resize a partial selection.
Height Sets the height of the image (in pixels). The default value
is 48.
Width Sets the width of the image (in pixels). The default value
for bitmaps is 48.
Requirements
None
See also
Image Editor for Icons
How to: Create an Icon or Other Image
How to: Use a Drawing Tool
How to: Work with Color
Accelerator Keys
How to: Use a Drawing Tool
7/27/2022 • 4 minutes to read • Edit Online
The Image Editor has freehand drawing and erasing tools that all work in the same way. You select the tool
and, if necessary, select foreground and background colors and size and shape options. You then move the
pointer to the image and click or drag to draw and erase.
Drawing Tools
You can select drawing tools from either the Image Editor toolbar or the Image menu. When you select the
Eraser tool, Brush tool, or Airbrush tool, the option selector displays that tool's options.
TIP
Tool tips appear when you hover your cursor over the buttons on the Image Editor toolbar. These tips will help you
identify the specific buttons mentioned here.
To select and use a drawing tool from the Image Editor toolbar
1. Select a button on the Image Editor toolbar.
The Eraser tool paints over the image with the current background color when you press the left
mouse button.
TIP
Instead of using the Eraser tool, you may find it more convenient to draw in the background color with
one of the drawing tools.
Custom Brushes
A custom brush is a rectangular portion of an image that you pick up and use like one of the Image Editor 's
ready-made brushes. All operations you can perform on a selection, you can perform on a custom brush as well.
To create a custom brush from a portion of an image
1. Select the part of the image that you want to use for a brush.
2. Hold the Shift key down, choose in the selection and drag it across the image, or go to menu Image >
Use Selection as Brush .
Your selection becomes a custom brush that distributes the colors in the selection across the image.
Copies of the selection are left along the dragging path. The more slowly you drag, the more copies are
made.
NOTE
Selecting the Use a Selection as Brush without first selecting a portion of the image will use the whole image
as a brush. The result of using a custom brush will also depend on whether you've selected an Opaque or
Transparent background.
Pixels in a custom brush that match the current background color are normally transparent: they don't paint
over the existing image. You can change this behavior so that background-color pixels paint over the existing
image.
You can use the custom brush like a stamp or a stencil to create different special effects.
To draw custom brush shapes in the background color
1. Select an opaque or transparent background.
2. Set the background color to the color in which you want to draw.
3. Position the custom brush where you want to draw.
4. Select the right mouse button. Any opaque regions of the custom brush are drawn in the background
color.
To double or halve the custom brush size
Press the Plus Sign (+ ) key to double the brush size, or the Minus Sign (- ) key to halve it.
To cancel the custom brush
Press Esc or choose another drawing tool.
Requirements
None
See also
Image Editor for Icons
How to: Create an Icon or Other Image
How to: Edit an Image
How to: Work with Color
Accelerator Keys
How to: Work with Color
7/27/2022 • 8 minutes to read • Edit Online
The Image Editor contains many features that specifically handle and customize colors. You can set a
foreground or background color, fill bounded areas with color, or select a color on an image to use as the current
foreground or background color. You can use tools on the Image Editor toolbar along with the colors palette in
the Colors window to create images.
All colors for monochrome and 16-color images are shown in the Colors palette in the Colors window. Along
with the 16 standard colors, you can create your own custom colors. Changing any of the colors in the palette
will immediately change the corresponding color in the image.
When working with 256-color icon and cursor images, the Colors property in the Properties window is used.
For more information, see Creating a 256-color icon or cursor.
True-color images can also be created. However, true color samples don't appear in the full palette in the Colors
window; they appear only in the foreground or background color indicator area. True colors are created using
the Custom Color Selector dialog box.
You can save customized color palettes on disk and reload them as needed. The color palette you used most
recently is saved in the Registry and automatically loaded the next time you start Visual Studio.
The Colors window has two parts:
The Colors Palette , which is an array of color samples that represent colors you can use. You can select
the samples to choose foreground and background colors when you're using the graphics tools.
The Color Indicator , which shows the foreground and background colors and selectors for screen and
inverse color.
Colors window
NOTE
The Screen color and Inverse color tools are only available for icons and cursors.
You can use the Colors window with the Image Editor toolbar.
To display the Colors window, right-click in an Image Editor pane and choose Show Colors Window ,
or go to menu Image > Show Colors Window .
To hide the Colors window, unpin the window (this action will allow the window to auto hide when it's
not in use) or select the Close button.
The Colors palette initially displays 16 standard colors. With displayed colors, you can also create your own
custom colors. You can then save and load a customized Color palette.
The Custom Color Selector dialog box allows you to customize the colors you use for your image with the
following properties:
Luminosity Bar Sets the luminosity for the color you select in the Gradient
Color Display box.
Select and drag the white arrow up the bar for greater
brightness or down for less. The Color box displays the
color you've selected and the effect of the luminosity you
set.
Color Lists the hue (color wheel value) of the color you're defining.
Values range from 0 to 240, where 0 is red, 60 is yellow, 120
is green, 180 is cyan, 200 is magenta, and 240 is blue.
Hue Lists the hue (color wheel value) of the color you're defining.
Values range from 0 to 240, where 0 is red, 60 is yellow, 120
is green, 180 is cyan, 200 is magenta, and 240 is blue.
Red Specifies the red value of the color you're defining. Values
range from 0 to 255.
Green Specifies the green value of the color you're defining. Values
range from 0 to 255.
Blue Specifies the blue value of the color you're defining. Values
range from 0 to 255.
You can save and load a Colors palette that contains customized colors. By default, the Colors palette most
recently used is automatically loaded when you start Visual Studio.
TIP
Since the Image Editor has no means to restore the default Colors palette, you should save the default Colors palette
under a name such as standard.pal or default.pal so that you can easily restore the default settings.
Use the Load Palette Colors dialog box to load special color palettes to use in your C++ project with following
properties:
File name Provides a space for you to type the name of the file you
want to open.
How To
To select foreground or background colors
Except for the Eraser , tools on the Image Editor toolbar draw with the current foreground or background color
when you press the left or right mouse button, respectively.
To select a foreground color, with the left mouse button, select the color you want on the Colors palette.
To select a background color, with the right mouse button, select the color you want on the Colors
palette.
To fill a bounded area of an image with a color
The Image Editor provides the Fill tool for filling any enclosed image area with the current drawing color or
the current background color.
To use the fill tool
1. Use the Image Editor toolbar or go to menu Image > Tools and select the Fill tool.
2. If necessary, choose drawing colors. In the Colors palette, select the left mouse button to select a
foreground color or the right mouse button to select a background color.
3. Move the Fill tool to the area you want to fill.
4. Select the left or right mouse button to fill with the foreground color or the background color,
respectively.
To pick up a color from an image to use elsewhere
The Select Color , or color-pickup, tool makes any color on the image the current foreground color or
background color, depending on whether you press the left or the right mouse button. To cancel the Select
Color tool, choose another tool.
1. Use the Image Editor toolbar or go to menu Image > Tools and select the Select Color tool.
2. Select the color you want to pick up from the image.
NOTE
After you pick up a color, the Image Editor reactivates the most recently used tool.
3. Draw using the left mouse button for the foreground color, or the right mouse button for the background
color.
To choose the background
When you move or copy a selection from an image, any pixels in the selection that match the current
background color are, by default, transparent and they don't obscure pixels in the target location.
You can switch from a transparent background (the default) to an opaque background, and back again. When
you use a selection tool, the Transparent Background and Opaque Background options appear in the
Option selector on the Image Editor toolbar.
TIP
For a shortcut, on the Image menu, select or clear Draw Opaque .
You can change the background color while a selection is already in effect to change which parts of the image
are transparent.
To invert the colors in a selection
The Image Editor provides a convenient way to invert colors in the selected part of the image so you can tell
how an image would appear with inverted colors.
To invert colors in the current selection, go to menu Image > Inver t Colors .
To customize or change colors on the colors palette
1. Go to menu Image > Adjust Colors .
2. In the Custom Color Selector dialog box, define the color by typing RGB or HSL values in the
appropriate text boxes or choose a color in the Gradient Color Display box.
3. Set the luminosity by moving the slider on the Luminosity bar.
4. Many custom colors are dithered. If you want the solid color closest to the dithered color, double-click the
Color box.
If you later decide you want the dithered color, move the slider on the Luminosity bar or move the cross
hairs in the Gradient Color Display box again to restore the dithering.
5. Select OK to add the new color.
To save a custom colors palette
1. Go to menu Image > Save Palette .
2. Navigate to the directory where you want to save the palette, and type a name for the palette.
3. Select Save .
To load a custom colors palette
1. Go to menu Image > Load Palette .
2. In the Load Color Palette dialog box, navigate to the correct directory and select the palette you want to
load. Color palettes are saved with a .pal file extension.
Requirements
None
See also
Image Editor for Icons
How to: Create an Icon or Other Image
How to: Edit an Image
How to: Use a Drawing Tool
Accelerator Keys
Accelerator Keys (C++ Image Editor for Icons)
7/27/2022 • 3 minutes to read • Edit Online
Below are the accelerator keys for the Image editor commands that are bound to keys by default. To change
accelerator keys, go to menu Tools > Options and choose Keyboard under the Environment folder. For more
information, see Identifying and Customizing Keyboard Shortcuts.
NOTE
The options available in dialog boxes, and the names and locations of menu commands you see, might differ from what is
described in Help depending on your active settings or edition. To change your settings, go to menu Tools > Impor t
and Expor t Settings . For more information, see Personalize the Visual Studio IDE.
Image.ShowTileGrid Ctrl + Shift + Alt + S Toggles the tile grid (selects or clears
the Tile grid option in the Grid
Settings dialog box).
Ctrl + Up Arrow
Requirements
None
See also
Image Editor for Icons
How to: Create an Icon or Other Image
How to: Edit an Image
How to: Use a Drawing Tool
How to: Work with Color
Menu Editor (C++)
7/27/2022 • 5 minutes to read • Edit Online
Menus allow you to arrange commands in a logical and easy-to-find fashion. With the Menu Editor , you can
create and edit menus by working directly with a menu bar that closely resembles the one in your finished
application.
TIP
While using the Menu Editor , in many instances, you can right-click to display a pop-up menu of frequently used
commands. The commands available depend on what the pointer is pointing to.
How To
The Menu Editor enables you:
To create a standard menu
1. Go to menu View > Resource View or View > Other Windows > Resource View and right-click on
the Menu heading. Choose Add Resource , then Menu .
2. Select the New Item box (the rectangle that contains Type Here) on the menu bar.
NOTE
To create a single-item menu on the menu bar, set the Popup property to False .
To create a submenu
1. Select the menu command for which you want to create a submenu.
2. In the New Item box that appears to the right, type the name of the new menu command. This new
command will appear first on the submenu menu.
3. Add more menu commands to the submenu menu.
To insert a new menu between existing menus
Select an existing menu name and press the Inser t key, or right-click on the menu bar and choose Inser t New .
The New Item box is inserted before the selected item.
To add commands to a menu
1. Create a menu. Then select a menu name, for example, File .
Each menu will expand and expose a new item box for commands. For example, you can add the
commands New , Open , and Close to a File menu.
2. In the new item box, type a name for the new menu command.
NOTE
The text you type appears in both the Menu Editor and in the Caption box in the Properties Window. You can
edit the properties for your new menu in either location.
TIP
You can define a mnemonic key (hot key) that allows the user to select the menu command. Type an ampersand (
& ) in front of a letter to specify it as the mnemonic. The user can select the menu command by typing that letter.
3. In the Proper ties window, select the menu command properties that apply. For details, see Menu
Command Properties.
4. In the Prompt box in the Proper ties window, type the prompt string you want to appear in your
application's status bar.
This step creates an entry in the string table with the same resource identifier as the menu command you
created.
NOTE
Prompts can only apply to menu items with a Popup property of True . For example, top-level menu items can
have prompts if they have sub-menu items. The purpose of a Prompt is to indicate what will happen if a user
selects the menu item.
NOTE
You can also drag, copy, and paste to other menus in other menu windows.
NOTE
Similarly, you can use the shortcut menu to perform other actions such as Copy, Cut, Paste, Insert New, Insert Separator,
Edit IDs, View as Pop-up, Check Mnemonics, etc.
Pop-up Menus
Pop-up menus display frequently used commands. They can be context sensitive to the location of the pointer.
Using pop-up menus in your application requires building the menu itself and then connecting it to application
code.
Once you've created the menu resource, your application code needs to load the menu resource and use
TrackPopupMenu to cause the menu to appear. Once the user has dismissed the pop-up menu by selecting
outside it, or has selected a command, that function will return. If the user chooses a command, that command
message will be sent to the window whose handle was passed.
NOTE
For Microsoft Foundation Class (MFC) library programs and ATL programs, use Code Wizards to hook menu commands
to code. For more information, see Adding an Event and Mapping Messages to Functions.
To create a pop-up menu, create a menu with an empty title and don't provide a Caption. Then, add a
menu command to the new menu. Move to the first menu command below the blank menu title (it has
the temporary caption Type Here) and type a Caption and any other information.
Repeat this process for any other menu commands in the pop-up menu and be sure to save the menu
resource.
To connect a pop-up menu to your application, for example, add a message handler for
WM_CONTEXTMENU, then add the following code to the message handler:
CMenu menu;
VERIFY(menu.LoadMenu(IDR_MENU1));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd());
NOTE
The CPoint passed by the message handler is in screen coordinates.
Normally, when you're working in the Menu Editor , a menu resource is displayed as a menu bar. However, you
might have menu resources that are added to the application's menu bar while the program is running.
To view a menu resource as a pop-up menu, right-click the menu and choose View as Popup .
This option is only a viewing preference and won't modify your menu.
TIP
To change back to the menu-bar view, select View as Popup again. This action removes the check mark and returns your
menu-bar view.
Requirements
Win32
See also
Resource Editors
Menu Commands
User-Interface Objects and Command IDs
Menus
Menus
Menu Commands (C++)
7/27/2022 • 4 minutes to read • Edit Online
The information below is organized according to the Menu properties that appear in the Properties Window
when you select a menu command. These are listed alphabetically although the Proper ties window also
enables you to view these properties by category.
Caption The text that labels the menu command (the menu name).
To make one of the letters in the caption of a menu
command the mnemonic key, precede it with an ampersand
(&).
Prompt Contains text to appear in the status bar when this menu
command is highlighted. The text is placed in the string table
with the same identifier as the menu command.
Right to Left Justify Right-justifies the menu command on the menu bar at run
time. Type: Bool. Default: False .
Right to Left Order Allows menu commands to display right to left when the
interface is localized to any language that reads right-to-left,
such as Hebrew or Arabic.
&Open...\tCtrl+O
The menu command in the Menu Editor is updated to reflect the new caption as you type it.
3. Create the accelerator-table entry in the Accelerator editor and assign it the same identifier as the menu
command. Use a key combination that you think will be easy to remember.
Your MFC application can display descriptive text for each of the menu commands a user may select. Display
descriptive text by assigning a text string to each menu command using the Prompt property in the
Proper ties window. If you have a string in the string table whose ID is the same as the command, an MFC
application will automatically display this string resource in the status bar of the running application when a
user hovers over a menu item.
To associate a menu command with a status bar text string in MFC applications, in the Menu Editor , select
the menu command. In the Properties Window, type the associated status bar text in the Prompt box.
In a C++ project, you can assign an access key (a mnemonic that allows the user to select the menu with the
keyboard) to your menus and menu commands.
To assign an access (shortcut) key to a menu command, type an ampersand ( & ) in front of a letter in the
menu name or command name to specify that letter as the corresponding access key.
For example, "&File" sets Alt +F as the shortcut key for the File menu in applications written for
Microsoft Windows.
The menu item will provide a visible cue that one of the letters has a shortcut key assigned to it. The letter
following the ampersand will appear underlined (contingent on the operating system).
NOTE
Make sure all the access keys on a menu are unique by right-clicking your menu and choosing Check Mnemonics .
Requirements
Win32
See also
Menu Editor
String Editor (C++)
7/27/2022 • 4 minutes to read • Edit Online
A string table is a Windows resource that contains a list of IDs, values, and captions for all the strings of your
application. For example, the status-bar prompts are located in the string table.
While developing an application, you can have several string tables — one for each language or condition.
However, an executable module has only one string table. A running application can reference several string
tables if you put the tables into different DLLs.
String tables make it easy to localize your application into different languages. If all strings are in a string table,
you can localize the application by translating the strings (and other resources) without changing source code.
This situation is more desirable than manually finding and replacing various strings in source files.
NOTE
Windows doesn't allow the creation of empty string tables. If you create a string table with no entries, it is deleted
automatically when you save the resource file.
How To
The String Editor enables you:
To find a string resource in the string table
1. Open the string table by double-clicking its icon in Resource View.
2. Go to menu Edit > Find and Replace and choose Find .
3. In the Find What box, select a previous search string from the drop-down list, or type the caption text or
resource identifier of the string you want to find.
4. Select any of the Find options and select Find Next .
TIP
To use regular expressions when searching files, use the Find in Files command in the Edit menu.
Type a regular expression to match a pattern or select the button to the right of the Find What box to display a list of
regular search expressions. When you select an expression from this list, it is substituted as the search text in the Find
What box.
If you use regular expressions, be sure the Use: Regular Expressions check box is selected.
NOTE
Null strings aren't allowed in Windows string tables. If you create an entry in the string table that's a null string,
you'll receive a message asking you to Please enter a string for this table entr y .
NOTE
If the ID or Value of the moved string conflicts with an existing ID or value in the destination file, either that ID or the
Value of the moved string changes.
NOTE
You can also edit a string's properties in the Properties window.
New line \n
Carriage return \r
Tab \t
Backslash (\) \\
Alert (bell) \a
NOTE
The String Editor doesn't support the full set of escaped ASCI characters. You can only use those listed above.
Requirements
Win32
See also
Resource Editors Strings
About Strings
Customizing window layouts
Toolbar Editor (C++)
7/27/2022 • 7 minutes to read • Edit Online
The Toolbar Editor enables you to create toolbar resources and convert bitmaps into toolbar resources. The
Toolbar Editor uses a graphical display. It shows a toolbar and buttons that closely resemble how they'll look in
a finished application.
The Toolbar Editor window shows two views of a button image, the same as the Image Editor window. A split
bar separates the two panes. To change the relative sizes of the panes, you can drag the split bar from side to
side. The active pane displays a selection border and above the two views of the image is the subject toolbar.
Toolbar Editor
The Toolbar Editor is similar to the Image Editor in functionality. The menu items, graphic tools, and bitmap
grid between the two are the same. There's a menu command in the Image menu to switch between the
Toolbar Editor and the Image Editor . For more information on using the Graphics toolbar, Colors palette, or
Image menu, see Image Editor.
You can create a new toolbar in a C++ project by converting a bitmap. The graphic from the bitmap converts to
the button images for a toolbar. Usually the bitmap contains several button images on a single bitmap, with one
image for each button. Images can be any size as the default is 16 pixels wide and the height of the image. You
can specify the size of the button images in the New Toolbar Resource dialog box. To specify sizes, choose
Toolbar Editor from the Image menu while in the Image Editor .
The New Toolbar Resource dialog box allows you to specify the width and height of the buttons you're adding
to a toolbar resource in a C++ project. The default is 16 × 15 pixels.
A bitmap that's used to create a toolbar has a maximum width of 2048. If you set the Button Width to 512, you
can only have four buttons. And, if you set the width to 513, you can only have three buttons.
The New Toolbar Resource dialog box has the following properties:
Button Width Provides a space for you to enter the width for the toolbar
buttons you're converting from a bitmap resource to a
toolbar resource.
Button Height Provides a space for you to enter the height for the toolbar
buttons you're converting from a bitmap resource to a
toolbar resource.
NOTE
The images are cropped to the width and height specified, and the colors are adjusted to use standard toolbar colors (16
colors).
By default, a toolbar displays a new or blank button at the right end of the toolbar. You can move this button
before editing it. When you create a new button, another blank button appears to the right of the edited button.
The blank button isn't saved when you save a toolbar.
A toolbar button has the following properties:
Height Sets the height of the button. The height of one button
changes the height of all buttons on the toolbar. 15 pixels is
recommended.
Width and Height apply to all buttons. A bitmap that is used to create a toolbar has a maximum width of 2048.
It means that if you set the button width to 512, you can only have four buttons. If you set the width to 513, you
can only have three buttons.
How To
The Toolbar Editor enables you:
To create new toolbars
1. In Resource View , right-click your .rc file and choose Add Resource . If you have an existing toolbar in
your .rc file, you can right-click the Toolbar folder and select Inser t Toolbar .
2. In the Add Resource dialog box, select Toolbar in the Resource Type list, then choose New .
If a plus sign (+ ) appears next to the Toolbar resource type, it means that toolbar templates are available.
Select the plus sign to expand the list of templates, select a template, and choose New .
To convert bitmaps to toolbar resources
1. Open an existing bitmap resource in the Image Editor. If the bitmap isn't already in your .rc file, right-click
the .rc file and choose Impor t . Then, navigate to the bitmap you want to add to your .rc file and select
Open .
2. Go to menu Image > Toolbar Editor .
The New Toolbar Resource dialog box appears. You can change the width and height of the icon
images to match the bitmap. The toolbar image is then displayed in the Toolbar Editor .
3. To finish the conversion, change the command ID of the button using the Properties window. Type the
new ID or select an ID from the drop-down list.
TIP
The Proper ties window contains a pushpin button in the title bar and selecting this enables or disables Auto
Hide for the window. To cycle through all the toolbar button properties without having to reopen the individual
property windows, turn Auto Hide off so the Proper ties window stays stationary.
You can also change the command IDs of the buttons on the new toolbar by using the Properties window.
To manage toolbar buttons
To create a new toolbar button
1. In Resource View expand the resource folder (for example, Project1.rc).
2. Expand the Toolbar folder and select a toolbar to edit, then either:
Assign an ID to the blank button at the right end of the toolbar. You can do so by editing the ID
property in the Properties Window. For example, you may want to give a toolbar button the same
ID as a menu option. In this case, use the drop-down list box to select the ID of the menu option.
Select the blank button at the right end of the toolbar in the Toolbar View pane and begin
drawing. A default button command ID is assigned (ID_BUTTON<n>).
To add an image to a toolbar as a button
1. In Resource View, open the toolbar by double-clicking it.
2. Next, open the image you'd like to add to your toolbar.
NOTE
If you open the image in Visual Studio, it will open in the Image Editor . You can also open the image in other
graphics programs.
A C T IO N ST EP
To insert a space before a button that isn't followed by a Drag the button to the right or down until it overlaps the
space next button about halfway.
To insert a space before a button that is followed by a space Drag the button until the right or bottom edge is just
and to keep the trailing space touching the next button or just overlaps it.
To insert a space before a button that is followed by a space Drag the button to the right or down until it overlaps the
and close up that following space next button about halfway.
To remove a space between buttons on a toolbar Select the button on one side of the space. Drag it toward
the button on the other side of the space until it overlaps
the next button about halfway.
NOTE
If there's no space on the side of the button that you're dragging away from and you drag the button more than halfway
past the adjacent button, the Toolbar Editor inserts a space on the opposite side of the button that you're dragging.
For example, to see the tool tip for the Print button in WordPad :
1. Open WordPad .
2. Hover your mouse pointer over the Print toolbar button and notice the word Print now is floating
under your mouse pointer.
3. Look at the status bar at the bottom of the WordPad window and notice that it now shows the text
Prints the active document .
Print is the tool tip name and Prints the active document is the description of the button for the status bar.
If you want this effect using the Toolbar Editor , set the Prompt property to Prints the active document\nPrint
.
Requirements
MFC or ATL
See also
Resource Editors
Menus and Other Resources
Version Information Editor (C++)
7/27/2022 • 2 minutes to read • Edit Online
Version information consists of company and product identification, a product release number, and copyright
and trademark notification. With the Version Information Editor , you create and maintain this data, which is
stored in the version information resource. The version information resource is not required by an application,
but it's a useful place to collect information that identifies the application. Version information is also used by
setup APIs.
NOTE
The Windows standard is to have only one version resource, named VS_VERSION_INFO.
A version information resource has an upper block and one or more lower blocks: a single fixed-information
block at the top and one or more version information blocks at the bottom (for other languages and/or
character sets). The top block has both editable numeric boxes and selectable drop-down lists. The lower blocks
have only editable text boxes.
NOTE
While using the Version Information Editor , in many instances you can right-click to display a shortcut menu of
resource-specific commands. For example, if you select while pointing to a block header entry, the shortcut menu shows
the New Version Block Info and Delete Version Block Info commands.
How To
The Version Information Editor enables you:
To edit a string in a version information resource
Select the item once to choose it, then again to begin editing it. Make changes directly in the Version
Information table or in the Properties window. The changes you make will be reflected in both places.
When editing the FILEFLAGS key in the Version Information Editor , notice you can't set the Debug , Private
Build , or Special Build properties in the Proper ties window for .rc files:
The Version Information Editor sets the Debug property with a #ifdef in the resource script, based
on the _DEBUG build flag.
If the Private Build key has a Value set in the Version Information table, the corresponding Private
Build property in the Proper ties window for the FILEFLAGS key will be True . If Value is empty, the
property will be False . Likewise, the Special Build key in the Version Information table is tied to the
Special Build property for the FILEFLAGS key.
You can sort the information sequence of the string block by selecting either the Key or the Value column
headings. These headings automatically rearrange the information into the selected sequence.
To add version information for another language (new version info block)
1. Open a version information resource by double-clicking it in Resource View.
2. Right-click within the version information table and choose New Version Info Block .
This command adds an additional information block to the current version information resource and
opens its corresponding properties in the Properties window.
3. In the Proper ties window, choose the appropriate language and character set for your new block.
To delete a version information block
1. Open the version information resource by double-clicking its icon in Resource View.
2. Right-click the block header you wish to delete and choose Delete Version Info Block .
This command deletes the selected header and leaves the rest of the version information intact. You can't
undo the action.
To access version information from within your program
If you want to access the version information from within your program, use the GetFileVersionInfo function and
the VerQueryValue function.
Requirements
Win32
See also
Resource Editors
Menus and Other Resources
Version Information (Windows)
Deploying Native Desktop Applications (Visual
C++)
7/27/2022 • 2 minutes to read • Edit Online
Deployment is the process by which you distribute a finished application or component to be installed on other
computers. Deployment planning starts when an application is created on a developer's computer. Deployment
ends when the application is installed and ready to run on a user's computer.
Visual Studio provides different technologies for deploying Windows applications. These include ClickOnce
deployment and Windows Installer deployment.
ClickOnce can be used to deploy C++ applications that target the common language runtime (CLR)—
mixed, pure, and verifiable assemblies. Although you can use Windows Installer to deploy a managed
application, we recommend that you use ClickOnce because it takes advantage of .NET Framework
security features such as manifest signing. ClickOnce does not support deployment of native C++
applications. For more information, see ClickOnce Deployment for Visual C++ Applications.
Windows Installer technology can be used to deploy either native C++ applications or C++ applications
that target the CLR.
The articles in this section of the documentation discuss how to ensure that a native Visual C++ application runs
on any computer that provides a supported target platform, which files you must include in an installation
package, and the recommended ways to redistribute the components that your application depends on.
In This Section
Deployment in Visual C++
Deployment Concepts
Understanding the Dependencies of a Visual C++ Application
Determining Which DLLs to Redistribute
Choosing a Deployment Method
Universal CRT deployment.
Redistributing Visual C++ Files
Deployment Examples
Redistributing Web Client Applications
ClickOnce Deployment for Visual C++ Applications
Running a C++ /clr Application on a Previous Runtime Version
Related Sections
Building C/C++ Isolated Applications and Side-by-side Assemblies
Deployment
Troubleshooting C/C++ Isolated Applications and Side-by-side Assemblies
Deployment in Visual C++
7/27/2022 • 3 minutes to read • Edit Online
Installation of your application on a computer other than your development computer is known as deployment.
When you deploy a Visual C++ application to another computer, you must install both the application and any
library files it depends on. Visual Studio enables three ways to deploy the Visual C++ libraries together with
your application: central deployment, local deployment, and static linking. Central deployment puts the library
files under the Windows directory, where all applications can access them automatically. Local deployment puts
the library files in the same directory as your application. You must redeploy any locally deployed libraries
yourself to update them. Static linking binds the library code into your application. You have to recompile and
redeploy your application to take advantage of any updates to the libraries when you use static linking.
In Visual Studio 2015, the Microsoft C Runtime library was refactored into version-specific local library
components, and a new Universal C Runtime library that is now part of Windows. For details on deployment of
the Universal CRT, see Universal CRT deployment.
Central deployment
In central deployment, library DLL files are installed in the Windows\System32 directory, or for 32-bit library files
on x64 systems, the Windows\SysWow64 directory. Centrally deployed library files are available to other
applications.
To centrally deploy Visual C++ libraries, you can use one of these two sources for the files to install:
Redistributable package files. These files are stand-alone command-line executables that contain all the
Visual C++ Redistributable libraries in compressed form. The latest Redistributable packages are
available from Microsoft Visual C++ Redistributable Latest Supported Downloads. When you use the
Redistributable packages for central deployment, Windows Update can service the libraries
independently.
Redistributable merge modules ( .msm files), which you can include in your application's Windows
Installer ( .msi ) file. This method is deprecated because libraries deployed this way can't be updated
automatically by Windows Update. For more information, see Redistributing by using merge modules.
A Redistributable package file installs all of the Visual C++ libraries for a particular system architecture. For
example, if your application is built for x64, you can use the vcredist_x64.exe package to install all the Visual
C++ libraries your application uses. You can program your application installer to run the package as a
prerequisite before you install your application.
Central deployment by using a Redistributable package enables Windows Update to automatically update the
Visual C++ libraries. For continued security and functionality, we recommend that you use the library DLLs in
your application instead of static libraries, and use Redistributable packages and central deployment instead of
local deployment.
Local deployment
In local deployment, library files are installed in your application folder together with the executable file.
Different versions of Visual C++ Redistributable libraries can be installed in the same folder because the file
name of each version includes its version number. For example, version 12 of the C++ runtime library is
msvcp120.dll , and version 14 is msvcp140.dll .
Expansions to a library may be spread across multiple extra DLLs, known as dot libraries. For example, some
functionality in the standard library released in Visual Studio 2017 version 15.6 was added into msvcp140_1.dll ,
to preserve the ABI compatibility of msvcp140.dll . If you use Visual Studio 2017 version 15.6 (toolset 14.13) or
later, you may need to locally deploy both these dot libraries and the main library. These separate dot libraries
will eventually be added to the base library, when the ABI changes.
Because Microsoft can't automatically update locally deployed Visual C++ libraries, we don't recommend local
deployment of these libraries. If you decide to use local deployment of the Redistributable libraries, we
recommend that you implement your own method of automatically updating the locally deployed libraries.
Static linking
In addition to dynamically linked libraries, Visual Studio supplies most of its libraries as static libraries. You can
statically link a static library to your application, that is, link the library object code directly into the application.
Static linking creates a single binary without a DLL dependency, so that you don't have to deploy the Visual C++
library files separately. However, we don't recommend this approach because statically linked libraries can't be
updated in place. To update a linked library when you use static linking, you have to recompile and redeploy
your application.
See also
Deploying desktop applications
Universal CRT deployment
Deployment Concepts
7/27/2022 • 2 minutes to read • Edit Online
This section discusses the main considerations for deploying C++ applications.
Library Dependencies
When a C/C++ application is built using functionality provided by the Visual C++ libraries, it becomes
dependent on the presence of those libraries at runtime. In order for the application to run, it must link, either
statically or dynamically, to the necessary Visual C++ libraries. If an application dynamically links to a Visual
C++ library, then when it runs that library must be present so it can be loaded. On the other hand, if the
application statically links to a Visual C++ library, then it does not need the corresponding DLLs to be present
on the user's computer. Static linking, however, has some negative effects, such as the increasing the size of the
application files, and making maintenance potentially more difficult. For more information, see Advantages of
using DLLs.
See also
Deploying Desktop Applications
Understanding the Dependencies of a Visual C++ Application
Understanding the Dependencies of a Visual C++
Application
7/27/2022 • 2 minutes to read • Edit Online
To determine which Visual C++ libraries an application depends on, you can view the project properties. (In
Solution Explorer, right-click on the project and choose Proper ties to open the Proper ty Pages dialog box.)
On Windows 8 and earlier, you can also use the Dependency Walker (depends.exe), which gives a more
comprehensive picture of the dependencies. For more recent versions of Windows the lucasg/Dependencies
tool provides similar functionality (this is a third-party tool not guaranteed by Microsoft.)
In the Proper ty Pages dialog box, you can examine various pages under Configuration Proper ties to
understand the dependencies. For example, if your project uses the MFC libraries and you choose Use of MFC ,
Use MFC in a Shared DLL on the Configuration Proper ties , General page, your application at run time
depends on MFC DLLs such as mfc<version>.dll. If your application doesn't use MFC, it might depend on the
CRT library if you choose a Runtime Librar y value of Multi-threaded Debug DLL (/MDd) or Multi-
threaded DLL (/MD) on the Configuration Proper ties , C/C++ , Code Generation page.
By using depends.exe, you can examine a list of DLLs that are linked to the application at load time, and a list of
its delay-loaded DLLs. If you want to get a complete list of DLLs that are dynamically loaded at run time, you can
use the profiling feature in depends.exe to test the application until you're sure that all code paths have been
exercised. When you end the profiling session, depends.exe shows which DLLs were dynamically loaded during
run time.
When you use depends.exe, be aware that a DLL might have a dependency on another DLL or on a specific
version of a DLL. You can use depends.exe on either the development computer or on a target computer. On the
development computer, depends.exe reports the DLLs that are required to support an application. If you have
trouble getting an application to run on a target computer, you can copy depends.exe to it and then open the
application in the tool so that you can determine whether any required DLLs are missing or incorrect.
When you know which DLLs your application depends on, you can determine the ones that you have to
redistribute with your application when you deploy it to another computer. In most cases, you don't have to
redistribute system DLLs, but you may have to redistribute DLLs for Visual C++ libraries. For more information,
see Determining Which DLLs to Redistribute.
See also
Deploying Desktop Applications
Determine which DLLs to redistribute
7/27/2022 • 8 minutes to read • Edit Online
When you build an application that uses library DLLs supplied by Visual Studio, users of your application must
also have those DLLs on their computers for the application to run. Because most users probably don't have
Visual Studio installed, you must provide these DLLs for them. Visual Studio makes these DLLs available as
Redistributable files that you can include in your application installer.
To make it easier to include the Redistributable DLLs with your installer, they're available as stand-alone
Redistributable packages. These packages are architecture-specific executables that use central deployment to
install the Redistributable files on a user's computer. For example, vc_redist.x86.exe installs the 32-bit libraries
for both x86 and x64 computers, vc_redist.x64.exe installs the 64-bit libraries for x64 computers, and
vcredist.ARM64.exe installs the libraries for ARM and ARM64 computers. We recommend central deployment
because Microsoft can use the Windows Update service to independently update these libraries. In addition to
the copy in your Visual Studio installation, the current Redistributable packages are available for download. For
links to the latest supported Redistributable packages for both current and older toolsets, see The latest
supported Visual C++ Redistributable downloads. Specific earlier versions of the Redistributable packages may
be found by searching my.visualstudio.com for "Visual C++ Redistributable Packages".
To make it easier to include the Redistributable DLLs with your installer, they're available as stand-alone
Redistributable packages. These packages are architecture-specific executables that use central deployment to
install the Redistributable files on a user's computer. For example, vcredist_x86.exe installs the 32-bit libraries
for both x86 and x64 computers, vcredist_x64.exe installs the 64-bit libraries for x64 computers, and
vcredist_ARM.exe installs the libraries for ARM computers. We recommend central deployment because
Microsoft can use the Windows Update service to independently update these libraries. In addition to the copy
in your Visual Studio installation, the current Redistributable packages are available for download. For links to
the latest supported Redistributable packages for both current and older toolsets, see The latest supported
Visual C++ downloads. Specific earlier versions of the Redistributable packages may be found by searching
my.visualstudio.com for "Visual C++ Redistributable Packages".
We only support using a Redistributable package that's the same as or newer than your toolset version. The
major version number of the Redistributable package you deploy must match the version of the Visual Studio
toolset used to create your application, and the minor version must be the same or higher. Visual Studio 2022,
2019, 2017 and 2015 all have compatible toolset version numbers. For these versions, any newer Visual Studio
Redistributable files may be used by apps built by a toolset from an older version. For example, Visual Studio
2022 Redistributable files may be used by apps built by using the Visual Studio 2017 or 2015 toolset. While they
may be compatible, we don't support using older Redistributable files in apps built by using a newer toolset. For
example, using the 2017 Redistributable files in apps built by using the 2019 toolset isn't supported.
It's also possible to include the Redistributable DLLs with your installer in merge modules. This method is now
deprecated because libraries deployed this way can't be updated automatically by Windows
Update. Redistributable merge modules, or Microsoft Installer modules ( .msm files), are optional components
available in the Visual Studio Installer. When installed, merge modules for the Redistributable DLLs are found in
your Visual Studio installation directory under %VCToolsRedistDir%\MergeModules\ . In Visual Studio 2015 and
earlier versions of Visual Studio, these files are found in your Program Files or Program Files (x86) directory in a
Common Files\Merge Modules subdirectory. For more information about use of these files, see Redistributing
components by using Merge Modules.
The individual Redistributable DLLs are also included in your installation of Visual Studio. By default, they're
installed in the Visual the %VCToolsRedistDir%\debug_nonredist\[architecture]\Microsoft.[toolset].[library]
folders, where [architecture] represents the target architecture, [toolset] represents the toolset version, and
[library] is the Debug library that has the debug DLLs.
It's also possible to include the Redistributable DLLs with your installer in merge modules. This method is now
deprecated because libraries deployed this way can't be updated automatically by Windows
Update. Redistributable merge modules for the Redistributable DLLs are found in your Program Files or
Program Files (x86) directory in a Common Files\Merge Modules subdirectory. For more information about use of
these files, see Redistributing components by using Merge Modules.
The individual Redistributable DLLs are also included in your installation of Visual Studio. By default, they're
installed in the Visual Studio 2015 installation directory in the
redist\debug_nonredist\[architecture]\Microsoft.[toolset].[library] folders, where [architecture] represents
the target architecture, [toolset] represents the toolset version, and [library] is the Debug library that has
the debug DLLs.
Use the latest version of any library DLL file, Redistributable package, or merge module found in these
directories. You may use these libraries for local deployment, by installing them in the same directory as your
application. We don't recommend local deployment because it makes you responsible for delivering updates to
your deployed applications. Central deployment by using the Redistributable packages is preferred.
To determine which DLLs you have to redistribute with your application, collect a list of the DLLs that your
application depends on. These DLLs are normally listed as import library inputs to the linker. Certain libraries,
such as vcruntime and the Universal C Runtime Library (UCRT), are included by default. If your app or one of its
dependencies uses LoadLibrary to dynamically load a DLL, that DLL may not be listed in the inputs to the linker.
One way to collect the list of dynamically loaded DLLs is to run Dependency Walker ( depends.exe ) on your app,
as described in Understanding the Dependencies of a Visual C++ Application. Unfortunately, this tool is
outdated and may report that it can't find certain DLLs.
When you have the list of dependencies, compare it to the list linked in the Redist.txt file found under the
Microsoft Visual Studio installation directory. Or, to the "REDIST list" of Redistributable DLLs that is referenced in
the "Distributable Code Files" section of the Microsoft Software License Terms for your copy of Visual Studio. For
Visual Studio 2022, see Distributable Code for Visual Studio 2022. For Visual Studio 2019, see Distributable
Code for Visual Studio 2019. For Visual Studio 2017, see Distributable Code for Microsoft Visual Studio 2017
(Includes Utilities, Extensibility, and BuildServer Files). For Visual Studio 2015, see Distributable Code for
Microsoft Visual Studio 2015 and Microsoft Visual Studio 2015 SDK (Includes Utilities and BuildServer Files). For
Visual Studio 2013, the list is available online in Distributable Code for Microsoft Visual Studio 2013 and
Microsoft Visual Studio 2013 SDK.
In Visual Studio versions before Visual Studio 2015, the C Runtime Library (CRT) was included as a
Redistributable DLL, in msvc[version].dll . In Visual Studio 2015, the functions in the CRT were refactored into
the vcruntime and the UCRT. The UCRT is now a system component in Windows 10 and later, managed by
Windows Update. It's available on all Windows 10 and later operating systems. To deploy your application to
earlier operating systems, you may need to redistribute the UCRT as well. An early version of the UCRT is
included in the Visual Studio Redistributable files. This version is only installed on operating systems earlier than
Windows 10, and only if no version of the UCRT is already installed. For an installable version of the UCRT for
downlevel systems as a Microsoft System Update package, see Windows 10 Universal C Runtime in the
Microsoft Download Center.
You can't redistribute all of the files that are included in Visual Studio. You're only permitted to redistribute the
files that are specified in Redist.txt or the online "REDIST list." You also can't redistribute debug versions of
your applications, or the debug versions of DLLs or libraries supplied by Microsoft. You may only copy debug
executables and libraries to machines you use for testing. For more information, see Choosing a deployment
method.
The following table describes some of the Visual C++ DLLs that your application might depend on.
VISUA L C ++ L IB RA RY DESC RIP T IO N A P P L IES TO
vcruntime[version].dll Runtime Library for native code. Applications that use the normal C and
C++ language startup and
termination services.
vccorlib[version].dll Runtime Library for managed code. Applications that use the C++
language services for managed code.
msvcp[version].dll and C++ Standard Library for native code. Applications that use the C++
msvcp[version_dotnumber].dll Standard Library.
concrt[version].dll Concurrency Runtime Library for Applications that use the Concurrency
native code. Runtime.
mfc[version].dll Microsoft Foundation Classes (MFC) Applications that use the MFC Library.
Library.
mfc[version][language].dll Microsoft Foundation Classes (MFC) Applications that use specific language
Library Resources. resources for MFC.
mfc[version]u.dll MFC Library with Unicode support. Applications that use the MFC Library
and require Unicode support.
mfcmifc80.dll MFC Managed Interfaces Library. Applications that use the MFC Library
with Windows Forms Controls.
mfcm[version].dll MFC Managed Library. Applications that use the MFC Library
with Windows Forms Controls.
mfcm[version]u.dll MFC Managed Library with Unicode Applications that use the MFC Library
support. with Windows Forms Controls and
require Unicode support.
vcamp[version].dll AMP Library for native code. Applications that use the C++ AMP
library code.
vcomp[version].dll OpenMP Library for native code. Applications that use the C++
OpenMP library code.
NOTE
You no longer need to redistribute the Active Template Library as a separate DLL. Its functionality has been moved to
headers and a static library.
For more information about how to redistribute these DLLs with your application, see Redistributing Visual C++
files. For examples, see Deployment examples.
Typically, you don't have to redistribute system DLLs because they're part of the operating system. However,
there might be exceptions, for example, when your application will run on several versions of Microsoft
operating systems. In this case, be sure to read the corresponding license terms. Also, try to get the system DLLs
upgraded either through Windows Update, service packs or by using Redistributable packages made available
by Microsoft.
See also
Choosing a deployment method
Deploying desktop applications
Choose a deployment method
7/27/2022 • 3 minutes to read • Edit Online
We recommend that you use Windows Installer for deployment. Windows Installer supports installation, repair,
and uninstallation, and also supports atomic updating of application files, dependencies, and registry entries.
Unless your Visual C++ application is self-contained and can be deployed by using a copy command, use
Windows Installer.
NOTE
Although ClickOnce deployment for Visual C++ native applications is possible in Visual Studio, it requires extra steps. For
more information, see ClickOnce deployment for Visual C++ applications.
See also
Deploying desktop applications
ClickOnce security and deployment
Deployment examples
Universal CRT deployment
7/27/2022 • 4 minutes to read • Edit Online
From Visual Studio .NET through Visual Studio 2013, each major release of the C++ compiler and tools has
included a new, standalone version of the Microsoft C Runtime (CRT) library. These standalone versions of the
CRT were independent from, and to various degrees, incompatible with each other. For example, the CRT library
used by Visual Studio 2012 was version 11, named msvcr110.dll, and the CRT used by Visual Studio 2013 was
version 12, named msvcr120.dll. Beginning in Visual Studio 2015, it's no longer the case. Visual Studio 2015 and
later versions of Visual Studio all use one Universal CRT.
The Universal CRT (UCRT) is a Microsoft Windows operating system component. It's included as part of the
operating system in Windows 10 or later, and Windows Server 2016 or later. The UCRT is available by using
Windows Update on older operating systems that are still in extended support. Local deployment of the
Universal CRT is supported, with some restrictions.
Central deployment
The preferred method to centrally install the Universal CRT is to use Microsoft Windows Update. The Universal
CRT is a Recommended update for all supported Microsoft Windows operating systems, so by default, most
machines install it as part of the regular update process. The initial release of the Universal CRT was KB2999226.
A later update with various bug fixes was made in KB3118401, and there have been more updates with further
bug fixes and new features. For more recent updates, search support.microsoft.com for "Universal C Runtime"
or "Universal CRT".
Not all Microsoft Windows computers regularly install updates by use of Windows Update, and some may not
install all Recommended updates. To support the use of applications built by using the Visual Studio 2015 and
later C++ toolsets on those machines, there are Universal CRT Redistributable files available for offline
distribution. Those redistributable files may be downloaded from one of the KB links above. The Universal CRT
Redistributable requires that the machine has been updated to the current service pack. So, for example, the
redistributable for Windows 7 will only install onto Windows 7 SP1, not Windows 7 RTM.
The Universal CRT is a fundamental dependency of the C++ libraries. The Visual C++ Redistributable (VCRedist)
installs the initial version of the Universal CRT (version 10.0.10240) on machines that don't already have one
installed. This version is sufficient to satisfy the C++ library dependencies. If your application depends on a
more recent version of the Universal CRT, you must use Windows Update to bring your machine fully up to date.
Or, install that version of the UCRT explicitly. It's best to install the Universal C Runtime by using Windows
Update or an MSU before you install the VCRedist. This installation order can help avoid multiple required
reboots.
Not all operating systems are eligible for the most recent Universal C Runtime via Windows Update. On
Windows 10 or Windows 11, the centrally deployed version matches the version of the operating system. To
update the Universal C Runtime further, you must update the operating system. For Windows Vista through
Windows 8.1, the latest available Universal C Runtime is based on the Windows 10 Anniversary Update (version
10.0.14393).
Local deployment
Local deployment of the Universal CRT is supported, but not recommended for both performance and security
reasons. The DLLs for local deployment are included as part of the Windows SDK, in the
Windows Kits\10\Redist\ucrt\DLLs subdirectory, by computer architecture. The DLLs required include
ucrtbase.dll and a set of APISet forwarder DLLs named api-ms-win-*.dll . The set of DLLs required on each
operating system varies. It's highly recommended that you include all of the DLLs when you deploy locally.
There are two restrictions on local deployment to be aware of:
On Windows 10 and Windows 11, the Universal CRT in the system directory is always used, even if an
application includes an application-local copy of the Universal CRT. It's true even when the local copy is
newer, because the Universal CRT is a core operating system component on Windows 10 and later.
Versions of Windows before Windows 8: The Universal CRT can't be packaged locally with a plugin, if it's
located anywhere but the main app executable directory. The APISet forwarder DLLs are unable to
resolve the ucrtbase.dll successfully in this case. Some recommended alternative solutions include:
Statically link the Universal CRT,
Centrally deploy the Universal CRT, or
Place the Universal CRT files in the same directory as the app.
IMPORTANT
Runtime library support for Windows XP is no longer available in the latest Visual C++ Redistributable for Visual Studio
2015, 2017, 2019 and 2022. The last redistributable to support Windows XP is version 16.7 (file version 14.27.29114.0).
If your Windows XP apps are deployed with or updated to a later version of the redistributable, the apps won't run. For
more information, and how to get a version of the redistributable that supports Windows XP, see Configuring programs
for Windows XP.
See also
Deployment in Visual C++
Redistributing Visual C++ Files
7/27/2022 • 5 minutes to read • Edit Online
NOTE
Are you here because you're looking for a download of one of the Visual C++ Runtime files? Go to the Latest supported
Visual C++ Redistributable downloads page.
The easiest way to locate the redistributable files is by using environment variables set in a developer command
prompt. In Visual Studio 2022, the redistributable files are in the %VCINSTALLDIR%Redist\MSVC\v143 folder. In the
latest version of Visual Studio 2019, you'll find the redistributable files in the %VCINSTALLDIR%Redist\MSVC\v142
folder. In both Visual Studio 2017 and Visual Studio 2019, they're also found in %VCToolsRedistDir% . In Visual
Studio 2015, these files can be found in %VCINSTALLDIR%redist\<locale> , where <locale> is the locale of the
redistributable packages.
In Visual Studio 2022 and 2019, merge module files are part of an optional installable component named C++
<version> Redistributable MSMs in the Visual Studio Installer. The merge modules are installed by default
as part of a C++ install in Visual Studio 2017 and Visual Studio 2015. When installed in Visual Studio 2022,
you'll find the redistributable merge modules in %VCINSTALLDIR%Redist\MSVC\v143\MergeModules . In the latest
version of Visual Studio 2019, the redistributable merge modules are in
%VCINSTALLDIR%Redist\MSVC\v142\MergeModules . In both Visual Studio 2019 and Visual Studio 2017, they're also
found in %VCToolsRedistDir%MergeModules . In Visual Studio 2015, they're found in
Program Files [(x86)]\Common Files\Merge Modules .
Redistributable merge modules must be included in the Windows Installer package (or similar installation
package) that you use to deploy your application. For more information, see Redistributing by using merge
modules. For an example see Walkthrough: Deploying a Visual C++ application by using a setup project.
Related articles
Redistributing by using merge modules
Describes how to use Visual C++ Redistributable merge modules to install the Visual C++ runtime libraries as
shared DLLs in the %windir%\system32\ folder.
Redistributing Visual C++ ActiveX Controls
Describes how to redistribute an application that uses ActiveX Controls.
Redistributing the MFC Library
Describes how to redistribute an application that uses MFC.
Redistributing an ATL application
Describes how to redistribute an application that uses ATL. In Visual Studio 2012 and later, no ATL library is
required.
Deployment Examples
Links to examples that demonstrate how to deploy Visual C++ applications.
Deploying Desktop Applications
Introduces Visual C++ deployment concepts and technologies.
Redistributing components by using merge modules
7/27/2022 • 3 minutes to read • Edit Online
IMPORTANT
In Visual Studio 2019 and later, merge modules for Visual C++ Redistributable files are deprecated. We don't recommend
you use them for application deployment. Redistributables installed using Merge modules can't be updated by Windows
Update because the detection mechanism depends on knowing details of the installing package. The Visual C++
Redistributable packages are known for each release, but packages that use MSMs are user generated. Microsoft can't
know the details of user-generated packages. Instead, we recommend you use central deployment of the Visual C++
Redistributable package. Central deployment installs the Redistributable files in the Windows %SYSTEMROOT%\system32\
folder for use by all applications and users. Central deployment by a Redistributable package makes it possible for
Microsoft to service runtime library files independently. And, an uninstall of your app can't break other applications that
also use central deployment. When you use a Redistributable package for central deployment, you aren't responsible for
tracking and updating the runtime libraries as part of your application maintenance: The Microsoft Update service
updates these libraries for you. Otherwise, an update to the runtime library files requires you to update and redeploy
your .msi installer. Your app could be vulnerable to bugs or security issues until you do.
Visual Studio includes merge modules ( .msm files) for each Visual C++ component that's licensed for
redistribution with an application. There are separate versions of the merge modules for each target platform.
When a merge module is compiled into a Windows Installer setup file, it enables the deployment of Visual C++
Redistributable files to that specific platform. You can't include merge modules for different versions of the same
DLL in one installer. In your installer setup file, specify that the merge modules are prerequisites for your
application.
You can use merge modules for either central deployment or local deployment. Users can't install centrally
deployed files unless they have administrator rights. Local deployment may allow a non-administrator to install
and run your app, but at the cost of independent serviceability.
The installation service reports an error if you attempt central deployment of older merge modules over newer
existing libraries. You should write your installer setup to handle this failure gracefully and not display an error
message. Your code can still deploy and run successfully despite this failure. For more information, see C++
binary compatibility between Visual Studio versions.
If you deploy your code only as an .msi installer, we recommend you don't include the merge modules in the
installer. Instead, report a failure to the user when the required Redistributable libraries aren't found. In the
failure dialog, include instructions on how to find and install the latest Redistributable package. For more
information and links to Redistributable packages, see The latest supported Visual C++ downloads.
The latest Redistributable packages and merge modules are compatible with code built using Visual Studio 2015
and later. Code built by versions of Visual Studio before 2015 require a separate Redistributable package.
See also
Redistributing Visual C++ files
Redistributing Visual C++ ActiveX Controls
7/27/2022 • 2 minutes to read • Edit Online
Visual C++ 6.0 supplies ActiveX controls you can use in applications that you then redistribute. These controls
are no longer included in Visual C++. Per the licensing agreements for Visual C++ 6.0, you can redistribute
these controls with applications developed in Visual C++.
NOTE
Visual C++ 6.0 is no longer supported by Microsoft.
For a list of the redistributable Visual C++ 6.0 ActiveX controls, see Common\Redist\Redist.txt on Disc 1 of the
Visual C++ 6.0 product CD.
When distributing applications, you must install and register the .ocx for the ActiveX control (using
Regsvr32.exe). In addition, you should make sure the target computer has current versions of the following
system files (an asterisk indicates the file needs to be registered):
Asycfilt.dll
Comcat.dll *
Oleaut32.dll *
Olepro32.dll *
Stdole2.tlb
If these DLLs are not available on the target system, you need to get them updated using the prescribed
mechanism for updating the corresponding operating system.
When using an ActiveX control that connects to a database, you also need to replicate the data source name on
the target computer. You can do this programmatically with functions such as ConfigDSN .
Some redistributable ActiveX controls have additional dependencies. For each .ocx file in the Os\System folder
on the Visual C++ 6.0 product CD, there is also a .dep file. For each .ocx file that you want to redistribute,
look for one or more USES entries in the corresponding .dep file. If a file is listed, you must ensure that the file
is on the target computer. Any DLLs directly supporting an .ocx file need to be registered. (For Regsvr32.exe to
succeed, the target computer must first contain all of the DLLs the control statically loads.) Furthermore, if a DLL
that is listed as a dependency also has a .dep file in the Os\System folder on the Visual C++ 6.0 CD, you must
also investigate that .dep file for USES entries.
See also
Redistributing Visual C++ Files
Redistributing the MFC Library
7/27/2022 • 3 minutes to read • Edit Online
If you dynamically link your application to the MFC library, you must redistribute the matching MFC DLL. For
example, if your MFC app is built by using the version of MFC that ships with Visual Studio 2015, you must
redistribute mfc140.dll or mfc140u.dll, depending on whether your app is compiled for narrow characters or
Unicode support.
NOTE
The mfc140.dll files were omitted from the redistributable files directory in Visual Studio 2015 RTM. You can use the
versions installed by Visual Studio 2015 in the Windows\system32 and Windows\syswow64 directories instead.
Because all MFC DLLs use the shared version of the C runtime library (CRT), You may also need to redistribute
the CRT. The version of MFC that ships with Visual Studio 2015 uses the universal CRT library, which is
distributed as part of Windows 10 and Windows 11. To run an MFC application built by using Visual Studio
2015 on earlier versions of Windows, you must redistribute the Universal CRT. For information on how to
redistribute the universal CRT as an operating system component or by using local deployment, see Introducing
the Universal CRT. To download the universal CRT for central deployment on supported versions of Windows,
see Windows 10 Universal C Runtime. Redistributable architecture-specific versions of ucrtbase.dll for local
deployment are found in the Windows SDK. By default, Visual Studio installs these in C:\Program Files
(x86)\Windows Kits\10\Redist\ucrt\DLLs\ in an architecture-specific sub-directory.
If your app is built by using an earlier version of the MFC library, you must redistribute the matching CRT DLL
from the redistributable files directory. For example, if your MFC application is built by using the Visual Studio
2013 (vc120) toolset, you must redistribute the msvcr120.dll. You also have to redistribute the matching mfc
<version> u.dll or mfc <version> .dll.
If you statically link your application to MFC (that is, if you specify Use MFC in a Static Librar y on the
General tab in the Proper ty Pages dialog box), you do not have to redistribute an MFC DLL. However,
although static linking may work for testing and internal deployment of applications, we recommend that you
do not use it to redistribute MFC. For more information about the recommended strategies for deploying Visual
C++ libraries, see Choosing a Deployment Method.
If your application uses the MFC classes that implement the WebBrowser control (for example, CHtmlView Class
or CHtmlEditView Class), we recommend that you also install the most current version of Microsoft Internet
Explorer so that the target computer will have the most current common control files. (At a minimum, Internet
Explorer 4.0 is required.) Information about how to install Internet Explorer components is available in "Article
185375: How To Create a Single EXE Install of Internet Explorer" on the Microsoft Support website.
If your application uses the MFC database classes (for example, CRecordset Class and CRecordView Class), you
must redistribute ODBC and any ODBC drivers that your application uses.
If your MFC application uses Windows Forms controls, you must redistribute mfcmifc80.dll with your
application. This DLL is a strong-name-signed .NET assembly that can be redistributed with an application in its
application local folder or by deploying it to the Global Assembly Cache (GAC) by using the Gacutil.exe (Global
Assembly Cache Tool).
If you redistribute an MFC DLL, make sure to redistribute the retail version and not the debug version. Debug
versions of the DLLs are not redistributable. The names of debug versions of the MFC DLLs end with a "d", for
example, Mfc140d.dll.
You can redistribute MFC by using either VCRedist_architecture.exe, merge modules that are installed with
Visual Studio, or by deploying the MFC DLL to the same folder as your application. For more information about
how to redistribute MFC, see Redistributing Visual C++ Files.
See also
Redistributing Visual C++ Files
Redistributing an ATL application
7/27/2022 • 2 minutes to read • Edit Online
Starting in Visual Studio 2012, Active Template Library (ATL) is a header-only library. ATL projects do not have a
Dynamic Link to ATL option. No redistributable ATL library is required.
If you redistribute an ATL executable application, you must register the .exe file (and any controls inside it) by
issuing the following command:
filename /regserver
filename /regserver
See also
Redistributing Visual C++ Files
Microsoft Visual C++ Redistributable latest
supported downloads
7/27/2022 • 4 minutes to read • Edit Online
The Visual C++ Redistributable installs Microsoft C and C++ (MSVC) runtime libraries. These libraries are
required by many applications built by using Microsoft C and C++ tools. If your app uses those libraries, a
Microsoft Visual C++ Redistributable package must be installed on the target system before you install your
app. The Redistributable package architecture must match your app's target architecture. The Redistributable
version must be at least as recent as the MSVC build toolset used to build your app. We recommend you use the
latest Redistributable available for your version of Visual Studio, with some exceptions noted below.
For details on how to install and redistribute Visual Studio components, see Redistributing Visual C++ Files.
A RC H IT EC T URE L IN K N OT ES
Download other languages and versions, including versions for long term servicing release channels (LTSC),
from my.visualstudio.com.
NOTE
Some of the downloads that are mentioned in this article are currently available on my.visualstudio.com. Make sure to log
in by using a Visual Studio Subscription account so that you can access the download links. If you're asked for credentials,
use your existing Visual Studio subscription account. Or, create a free account by selecting the link in No account?
Create one!
Notes
Visual Studio versions since Visual Studio 2015 share the same Redistributable files. For example, any
apps built by the Visual Studio 2015, 2017, 2019, or 2022 toolsets can use the latest Microsoft Visual
C++ Redistributable. However, the version of the Microsoft Visual C++ Redistributable installed on the
machine must be the same or higher than the version of the Visual C++ toolset used to create your
application. For more information about which version of the Redistributable to install, see Determining
which DLLs to redistribute.
Windows XP Suppor t : Microsoft ended support for Windows XP on April 8, 2014. Current versions of
the Visual C++ Redistributable for Visual Studio 2015-2022 only support Windows Vista, 7, 8.1, 10, and
11. The last version of the Visual C++ Redistributable that works on Windows XP shipped in Visual Studio
2019 version 16.7 (file versions starting with 14.27 ). The Redistributable is available in the
my.visualstudio.com Downloads section as Visual C++ Redistributable for Visual Studio 2019 -
Version 16.7 . Use the Search box to find this version. To download the files, select the platform and
language you need, and then choose the Download button.
A RC H IT EC T URE VERSIO N L IN K
Other versions
Multibyte MFC Library for Visual Studio 2013. This MFC add-on for Visual Studio 2013 contains the
multibyte character set (MBCS) version of the Microsoft Foundation Class (MFC) Library.
Visual C++ 2013 Runtime for Sideloaded Windows 8.1 apps. For more information, see C++ Runtime for
Sideloaded Windows 8.1 apps on the C++ Team Blog.
A RC H IT EC T URE VERSIO N L IN K
A RC H IT EC T URE VERSIO N L IN K
A RC H IT EC T URE VERSIO N L IN K
Redistributable files for X86, X64, and IA64 architectures are available from Microsoft Visual C++ 2005
Service Pack 1 Redistributable Package MFC Security Update.
Deployment Examples
7/27/2022 • 2 minutes to read • Edit Online
This section contains examples demonstrating how to deploy Visual C++ applications.
Examples
Walkthrough: Deploying a Visual C++ Application By Using a Setup Project
Walkthrough: Deploying a Visual C++ Application to an Application-local Folder
Walkthrough: Deploying a Visual C++ Application By Using the Visual C++ Redistributable Package
Preparing a Test Machine To Run a Debug Executable
See also
Walkthrough: Manually Deploying a ClickOnce Application
Deploying Desktop Applications
Walkthrough: Deploy a Visual C++ application by
using a setup project
7/27/2022 • 15 minutes to read • Edit Online
In this walkthrough, you'll create a sample app in Visual Studio, then create a setup project to deploy your app to
another computer.
Instructions for creating a new project vary depending on which version of Visual Studio you've installed. To see
the documentation for your preferred version of Visual Studio, use the Version selector control. It's found at the
top of the table of contents on this page.
Prerequisites
You need the following components to complete this walkthrough:
A computer with Visual Studio 2022 installed. The installation must include the Desktop development
with C++ workload, and the C++ MFC for latest v143 build tools (x86 & x64) optional
component.
The Microsoft Visual Studio Installer Projects extension. The extension is free for Visual Studio developers
and adds the functionality of the setup and deployment project templates to Visual Studio.
To test your deployment, another computer that doesn't have the Visual C++ libraries installed.
To install C++ and MFC in Visual Studio 2022
If you have Visual Studio installed, but you don't have the C++ or MFC components installed, you can add them
now.
1. Launch the Visual Studio Installer program from the Windows Start menu.
2. In Visual Studio Installer, choose the Modify button next to your installed version of Visual Studio.
3. In the Modifying dialog, under the Workloads tab, scroll down to the Desktop Development with
C++ tile. If the tile checkbox isn't checked, check the checkbox.
4. To the side of the dialog under Installation details , expand the Desktop Development with C++
node, then expand the Optional node. If it isn't already checked, add a check to the C++ MFC for latest
v143 build tools (x86 & x64) component.
5. Choose the Modify button to modify your Visual Studio installation. When installation completes, exit the
Visual Studio installer.
To install the Installer Projects extension
1. In Visual Studio, select the Extensions > Manage Extensions menu item.
2. In the Manage Extensions dialog, expand Online > Visual Studio Marketplace > Tools and select
Setup & Deployment .
3. In the list of extensions, select Microsoft Visual Studio Installer Projects 2022 . Choose the
Download button.
4. A notification appears at the bottom of the dialog that tells you the modification will begin when all
Microsoft Visual Studio windows are closed. Close the dialog.
5. Close Visual Studio. The download and install process begins. You may need to accept a User Account
Control elevation prompt to allow the installer to change Visual Studio.
6. In the VSIX Installer dialog, choose Modify to install the extension. When the modifications complete,
choose Close to dismiss the dialog.
A computer with Visual Studio 2019 installed. The installation must include the Desktop development
with C++ workload, and the C++ MFC for latest v142 build tools (x86 & x64) optional
component.
The Microsoft Visual Studio Installer Projects extension. The extension is free for Visual Studio developers
and adds the functionality of the setup and deployment project templates to Visual Studio.
To test your deployment, another computer that doesn't have the Visual C++ libraries installed.
To install C++ and MFC in Visual Studio 2019
If you have Visual Studio installed, but you don't have the C++ or MFC components installed, you can add them
now.
1. Launch the Visual Studio Installer program from the Windows Start menu.
2. In Visual Studio Installer, choose the Modify button next to your installed version of Visual Studio.
3. In the Modifying dialog, under the Workloads tab, scroll down to the Desktop Development with
C++ tile. If the tile checkbox isn't checked, check the checkbox.
4. To the side of the dialog under Installation details , expand the Desktop Development with C++
node, then expand the Optional node. If it isn't already checked, add a check to the C++ MFC for latest
v142 build tools (x86 & x64) component.
5. Choose the Modify button to modify your Visual Studio installation. When installation completes, exit the
Visual Studio installer.
To install the Installer Projects extension
1. In Visual Studio, select the Extensions > Manage Extensions menu item.
2. In the Manage Extensions dialog, expand Online > Visual Studio Marketplace > Tools and select
Setup & Deployment .
3. In the list of extensions, select Microsoft Visual Studio Installer Projects . Choose the Download
button.
4. A notification appears at the bottom of the dialog that tells you the modification will begin when all
Microsoft Visual Studio windows are closed. Close the dialog.
5. Close Visual Studio. The download and install process begins. You may need to accept a User Account
Control elevation prompt to allow the installer to change Visual Studio.
6. In the VSIX Installer dialog, choose Modify to install the extension. When the modifications complete,
choose Close to dismiss the dialog.
A computer with Visual Studio 2017 installed. The installation must include the Desktop development
with C++ workload, and the Visual C++ MFC for x86 and x64 optional component.
The Microsoft Visual Studio Installer Projects extension. The extension is free for Visual Studio developers
and adds the functionality of the setup and deployment project templates to Visual Studio.
To test your deployment, another computer that doesn't have the Visual C++ libraries installed.
To install C++ and MFC in Visual Studio 2017
If you have Visual Studio 2017 installed, but you don't have the C++ or MFC components installed, you can add
them now.
1. Launch the Visual Studio Installer program from the Windows Start menu.
2. In Visual Studio Installer, choose the Modify button next to your installed version of Visual Studio 2017.
3. In the Modifying dialog, under the Workloads tab, scroll down to the Desktop Development with
C++ tile. If the tile checkbox isn't checked, check the checkbox.
4. To the side of the dialog under Installation details , expand the Desktop Development with C++
node, then expand the Optional node. If it isn't already checked, add a check to the Visual C++ MFC
for x86 and x64 component.
5. Choose the Modify button to modify your Visual Studio installation. When installation completes, exit the
Visual Studio installer.
To install the Installer Projects extension
1. In Visual Studio, select the Tools > Extensions and Updates menu item.
2. In the Extensions and Updates dialog, expand Online > Visual Studio Marketplace > Tools and select
Setup & Deployment . Set the Sor t by dropdown to Most Downloads .
3. In the list of extensions, select Microsoft Visual Studio Installer Projects . Choose the Download
button.
4. A notification appears at the bottom of the dialog that tells you the modification will begin when all
Microsoft Visual Studio windows are closed. Close the dialog.
5. Close Visual Studio. The download and install process begins. You may need to accept a User Account
Control elevation prompt to allow the installer to change Visual Studio.
6. In the VSIX Installer dialog, choose Modify to install the extension. When the modifications complete,
choose Close to dismiss the dialog.
A computer with Visual Studio installed. The installation must include the Visual C++ programming
language tools, and the Microsoft Foundation Classes for C++ optional component.
The Microsoft Visual Studio Installer Projects extension. The extension is free for Visual Studio developers
and adds the functionality of the setup and deployment project templates to Visual Studio.
To test your deployment, another computer that doesn't have the Visual C++ libraries installed.
To install C++ and MFC in Visual Studio 2015
The Visual Studio 2015 setup program doesn't install Visual C++ and MFC by default. If you have Visual Studio
2015 installed, but you don't have the C++ or MFC components installed, you can add them now.
1. Open the Windows Start menu and enter Add Remove Programs . Open the control panel app from the
results list.
2. Find your Microsoft Visual Studio 2015 installation in the list of installed programs. Find the Modify
option for Microsoft Visual Studio 2015 and choose it to launch the Visual Studio setup program.
3. In the Visual Studio setup program, choose the Modify button.
4. Under the Features tab, expand Programming Languages > Visual C++ . Select Common Tools for
Visual C++ 2015 and Microsoft Foundation Classes for C++ . Choose the Next button to continue.
5. On the Selected Features page, choose the UPDATE button to install the required components. When the
update is complete, choose Close to dismiss the setup program.
To install the Installer Projects extension
1. In Visual Studio, select the Tools > Extensions and Updates menu item.
2. In the Extensions and Updates dialog, expand Online > Visual Studio Galler y > Tools and select
Setup & Deployment . Set the Sor t by dropdown to Most Downloads .
3. In the list of extensions, select Microsoft Visual Studio 2015 Installer Projects . Choose the
Download button.
4. When the download completes, close the Extensions and Updates dialog, then close Visual Studio.
5. Open the downloaded VSI_bundle.exe file. Choose Install in the Visual Studio setup program. You may
need to accept a User Account Control elevation prompt to allow the installer to change Visual Studio.
Choose Close when the installer completes to dismiss the dialog.
2. At the top of the dialog, type MFC in the search box and then choose MFC App from the results list. (If
the MFC App template is missing, see To install C++ and MFC in Visual Studio 2022.) Choose the Next
button to continue.
3. In the Configure your new project page, enter a name for the project, such as MyMFCApp. Choose the
Create button.
4. In the MFC Application Wizard dialog, choose Finish to create the default MFC app project. The wizard
creates your MFC app and opens the project in Visual Studio.
5. In Visual Studio, change the active solution configuration to Release and the Active solution platform to
x86 . On the Build menu, select Configuration Manager . In the Configuration Manager dialog box,
select Release from the Active solution configuration drop-down box. Choose Close to save your
changes.
6. Select the Build > Build Solution menu item to build the solution. The setup project uses the output of
this MFC application project.
To create the app project in Visual Studio 2019
1. On the menu bar, choose File > New > Project to open the Create a New Project dialog box.
2. At the top of the dialog, type MFC in the search box and then choose MFC App from the results list. (If
the MFC App template is missing, see To install C++ and MFC in Visual Studio 2019.) Choose the Next
button to continue.
3. In the Configure your new project page, enter a name for the project, such as MyMFCApp. Choose the
Create button.
4. In the MFC Application Wizard dialog, choose Finish to create the default MFC app project. The wizard
creates your MFC app and opens the project in Visual Studio.
5. In Visual Studio, change the active solution configuration to Release . On the Build menu, select
Configuration Manager . In the Configuration Manager dialog box, select Release from the Active
solution configuration drop-down box. Choose Close to save your changes.
6. Select the Build > Build Solution menu item to build the solution. The setup project uses the output of
this MFC application project.
To create the app project in Visual Studio 2017
1. On the menu bar, choose File > New > Project to open the New Project dialog box.
2. In the New Project dialog tree view control, select Installed > Visual C++ > MFC/ATL .
3. In the center pane, select the MFC App template. (If the MFC App template is missing, see To install C++
and MFC in Visual Studio 2017.) Change the Name to MyMFCApp. Choose OK to launch the MFC
Application wizard.
4. In the MFC Application Wizard dialog, choose Finish to create the default MFC app project. The wizard
creates your MFC app and opens the project in Visual Studio.
5. In Visual Studio, change the active solution configuration to Release . On the Build menu, select
Configuration Manager . In the Configuration Manager dialog box, select Release from the Active
solution configuration drop-down box. Choose Close to save your changes.
6. Select the Build > Build Solution menu item to build the solution. The setup project uses the output of
this MFC application project.
To create the app project in Visual Studio 2015
1. On the menu bar, choose File > New > Project to open the New Project dialog box.
2. In the New Project dialog tree view control, select Installed > Templates > Visual C++ > MFC .
3. In the center pane, select the MFC Application template. (If the MFC Application template is missing, see
To install C++ and MFC in Visual Studio 2015.) Change the Name to MyMFCApp. Choose OK to launch
the MFC Application wizard.
4. In the MFC Application Wizard dialog, choose Finish to create the default MFC app project. The wizard
creates your MFC app and opens the project in Visual Studio.
5. In Visual Studio, change the active solution configuration to Release . On the Build menu, select
Configuration Manager . In the Configuration Manager dialog box, select Release from the Active
solution configuration drop-down box. Choose Close to save your changes.
6. Select the Build > Build Solution menu item to build the solution. The setup project uses the output of
this MFC application project.
See also
Deployment Examples
Walkthrough: Deploying a Visual C++ Application
to an Application-local Folder
7/27/2022 • 2 minutes to read • Edit Online
Describes how to deploy a Visual C++ application by copying files to its folder.
Prerequisites
A computer that has Visual Studio installed.
Another computer that doesn't have the Visual C++ libraries.
To deploy an application to an application-local folder
1. Create and build an MFC application by following the steps in Walkthrough: Deploying a Visual C++
Application By Using a Setup Project.
2. Copy the appropriate MFC and C Run-Time (CRT) library files from the Visual Studio installation directory
in the \VC\redist\version folder, and then paste them in the \Release\ folder of your MFC project. For
more information about other files that you might have to copy, see Determining Which DLLs to
Redistribute.
3. Run the MFC application on a second computer that doesn't have the Visual C++ libraries.
a. Copy the contents of the \Release\ folder and paste them in the application folder on the second
computer.
b. Run the application on the second computer.
The application runs successfully because the Visual C++ libraries are available in the application-local
folder.
See also
Deployment Examples
Walkthrough: Deploy a Visual C++ application by
using the Visual C++ Redistributable Package
7/27/2022 • 3 minutes to read • Edit Online
To run apps that use Visual C++ runtime libraries, the target machine must have a compatible Microsoft Visual
C++ Redistributable Package installed. This step-by-step article describes one way to deploy both the Microsoft
Visual C++ Redistributable Package and your Visual C++ application. You can use any installer technology to
deploy your app. This walkthrough uses the IExpress Wizard to create a self-extracting executable installer that
installs the Redistributable and an application.
Prerequisites
You must have these components to complete this walkthrough:
A computer that has Visual Studio installed.
Another computer that doesn't have the Visual C++ libraries.
To use the Microsoft Visual C++ Redistributable Package to deploy an application
1. If you need a sample application to deploy, create and build an MFC application by following the steps in
Walkthrough: Deploying a Visual C++ application by using a setup project. This walkthrough assumes
your app is named MyMFCApp like the sample, but you can change the name to match your app.
2. Create a file, name it setup.bat , and add the following commands to it. If your app has a different name,
change MyMFCApp to the name of your app. If your app targets x86, change "Program Files" to "Program
Files (x86)". Remove the leading colons ( :: ) to uncomment the line that installs the Redistributable for
your target architecture.
@echo off
REM Choose one of the following Redistributable files to install
::vc_redist.x86.exe REM remove leading :: to install Redistributable for x86
::vc_redist.x64.exe REM remove leading :: to install Redistributable for x64
::vc_redist.arm64.exe REM remove leading :: to install Redistributable for ARM64
mkdir "C:\Program Files\MyMFCApp"
copy MyMFCApp.exe "C:\Program Files\MyMFCApp"
i. On the Show window page, select Default and then choose Next .
j. On the Finished message page, select No message . Choose Next .
k. On the Package Name and Options page, enter a name for your self-extracting setup file, select
the Store files using Long File Name inside Package option, and then choose Next . The end
of the file name must be Setup.exe —for example, MyMFCAppSetup.exe .
l. On the Configure restar t page, select No restar t . Choose Next .
m. On the Save Self Extraction Directive page, select Save Self Extraction Directive (SED) file .
Choose Next .
n. On the Create package page, choose Next . Choose Finish .
4. Test the self-extracting setup file on the other computer that doesn't have the Visual C++ libraries:
a. On the other computer, download a copy of the setup file. Then, run the setup and follow the steps
that it provides. Depending on the options selected, installation might require you to accept a User
Account Control elevation request, or to run the installer by using the Run as administrator
command.
b. Run the app.
The self-extracting setup file installs the app that's in the folder you specified in setup.bat . The
app should run successfully because the Microsoft Visual C++ Redistributable Package installer is
included in the self-extracting setup file.
IMPORTANT
To determine which version of the runtime is installed, the installer checks the registry key
\HKLM\SOFTWARE\Microsoft\VisualStudio\<version>\VC\Runtimes\<platform>\Version . If the
currently installed version is newer than the version that the installer is attempting to install, the installer
returns success without installing the older version and leaves an additional entry on the installed
programs page in the Control Panel.
See also
Deployment examples
Prepare a test machine to run a debug executable
7/27/2022 • 2 minutes to read • Edit Online
Apps built by using Visual C++ require the vcruntime and other libraries to run. Debug versions of apps often
require the corresponding debug versions of the libraries. You must deploy these libraries on your test machine
to test the debug version of your app. To identify which DLLs you must deploy, follow the steps in
Understanding the dependencies of a Visual C++ application. Typically, debug versions of Visual C++ library
DLLs have names that end in "d". For example, the debug version of vcruntime140.dll is named
vcruntime140d.dll .
NOTE
Debug versions of an application aren't redistributable, and debug versions of the Visual C++ library DLLs are also not
redistributable. You may deploy debug versions of applications and Visual C++ DLLs only to your other computers, for
the sole purpose of debugging and testing the applications on a computer that doesn't have Visual Studio installed. For
more information, see Redistributing Visual C++ files.
See also
Deployment in Visual C++
Windows Installer command line options
Deployment examples
Remote debugging
Redistributing Web Client Applications
7/27/2022 • 2 minutes to read • Edit Online
If your application uses the MFC classes implementing the WebBrowser control (for example, CHtmlView or
CHtmlEditView ), Microsoft Internet Explorer 4.0 or later must at least be minimally installed on the target
computer.
Installing the latest version of Internet Explorer also ensures that the target computer has the latest common
control files. For more information, see Install and Deploy Internet Explorer 11.
See also
Deploying Desktop Applications
ClickOnce Deployment for Visual C++ Applications
7/27/2022 • 2 minutes to read • Edit Online
Visual Studio provides two different technologies for deploying Windows applications: ClickOnce deployment or
Windows Installer deployment.
NOTE
Visual Studio does support ClickOnce in the Visual C# and Visual Basic development environments. If your Visual Studio
C++ project is a dependency of a Visual C# project, you can publish the application (including its dependencies) using
ClickOnce deployment from the Visual C# development environment.
To deploy a Visual C++ application using ClickOnce, you first have to build a ClickOnce Application Manifest and
a ClickOnce Deployment Manifest using the Mage.exe (Manifest Generation and Editing Tool) or its graphical
user interface version (for information, see MageUI.exe (Manifest Generation and Editing Tool, Graphical Client)).
You first use Mage.exe to build the application manifest; the resulting file will have the extension .manifest. You
then use Mage.exe to build the deployment manifest; the resulting file will have the extension .application. You
then sign the manifests.
The application manifest must specify the target processor (x86 , x64 , or ARM ). See Deploying Prerequisites for
64-bit Applications for information on these options.
Also, the name of the application and deployment manifests must be different from the name of the C++
application. This avoids conflict between the application manifest created by Mage.exe and the external manifest
that is part of the C++ application.
Your deployment will need to install any Visual C++ libraries on which your application depends. To determine
the dependencies for a particular application, you can use depends.exe or the DUMPBIN utility with the
/DEPENDENTS option. For more information on dependencies, see Understanding the Dependencies of a Visual
C++ Application. You might need to run VCRedist.exe; this utility installs Visual C++ libraries on the target
computer.
You may also need to build a bootstrapper (prerequisites installer) for your application to deploy prerequisite
components; for information on the bootstrapper, see Creating Bootstrapper Packages.
For a more detailed description of the technology, see ClickOnce Security and Deployment. For a detailed
example of ClickOnce deployment, see Walkthrough: Manually Deploying a ClickOnce Application.
See also
Mage.exe (Manifest Generation and Editing Tool)
MageUI.exe (Manifest Generation and Editing Tool, Graphical Client)
Makecert.exe (Certificate Creation Tool)
Deploying Desktop Applications
Deploying Applications, Services, and Components
ClickOnce Security and Deployment
Creating Bootstrapper Packages
.NET Programming with C++/CLI (Visual C++)
Native and .NET Interoperability
Running a C++ /clr Application on a Previous
Runtime Version
7/27/2022 • 2 minutes to read • Edit Online
Unless otherwise specified, a C++ .NET Framework application is built to run on the common language runtime
(CLR) version that the compiler uses to build the application. However, it is possible for an .exe application that is
built for one version of the runtime to run on any other version that provides the required functionality.
To accomplish this, provide an app.config file that contains runtime version information in the supportedRuntime
tag.
At run time, the app.config file must have a name of the form filename.ext.config, where filename.ext is the name
of the executable that started the application, and it must be in the same directory as the executable. For
example, if your application is named TestApp.exe, the app.config file would be named TestApp.exe.config.
If you specify more than one runtime version and the application runs on a computer that has more than one
installed runtime version, the application uses the first version that is specified in the config file and is installed.
See also
Deploying Desktop Applications
C++ Attributes for COM and .NET
7/27/2022 • 4 minutes to read • Edit Online
Microsoft defines a set of C++ attributes that simplify COM programming and .NET Framework common
language runtime development. When you include attributes in your source files, the compiler works with
provider DLLs to insert code or modify the code in the generated object files. These attributes aid in the creation
of .idl files, interfaces, type libraries, and other COM elements. In the integrated development environment (IDE),
attributes are supported by the wizards and by the Properties window.
While attributes eliminate some of the detailed coding needed to write COM objects, you need a background in
COM fundamentals to best use them.
NOTE
If you are looking for C++ standard attributes, see Attributes.
Purpose of Attributes
Attributes extend C++ in directions not currently possible without breaking the classic structure of the language.
Attributes allow providers (separate DLLs) to extend language functionality dynamically. The primary goal of
attributes is to simplify the authoring of COM components, in addition to increasing the productivity level of the
component developer. Attributes can be applied to nearly any C++ construct, such as classes, data members, or
member functions. The following is a highlight of benefits provided by this new technology:
Exposes a familiar and simple calling convention.
Uses inserted code, which, unlike macros, is recognized by the debugger.
Allows easy derivation from base classes without burdensome implementation details.
Replaces the large amount of IDL code required by a COM component with a few concise attributes.
For example, to implement a simple event sink for a generic ATL class, you could apply the event_receiver
attribute to a specific class such as CMyReceiver . The event_receiver attribute is then compiled by the Microsoft
C++ compiler, which inserts the proper code into the object file.
[event_receiver(com)]
class CMyReceiver
{
void handler1(int i) { ... }
void handler2(int i, float j) { ... }
}
You can then set up the CMyReceiver methods handler1 and handler2 to handle events (using the intrinsic
function __hook) from an event source, which you can create using event_source.
NOTE
Attribute usage does not alter the contents of the source file. The only time the generated attribute code is visible is
during debugging sessions. In addition, for each source file in the project, you can generate a text file that displays the
results of the attribute substitution. For more information on this procedure, see /Fx (Merge Injected Code) and
Debugging Injected Code.
Like most C++ constructs, attributes have a set of characteristics that defines their proper usage. This is referred
to as the context of the attribute and is addressed in the attribute context table for each attribute reference topic.
For example, the coclass attribute can only be applied to an existing class or structure, as opposed to the
cpp_quote attribute, which can be inserted anywhere within a C++ source file.
Attribute Contexts
C++ attributes can be described using four basic fields: the target they can be applied to (Applies To ), if they
are repeatable or not (Repeatable ), the required presence of other attributes (Required Attributes ), and
incompatibilities with other attributes (Invalid Attributes ). These fields are listed in an accompanying table in
each attribute's reference topic. Each of these fields is described below.
Applies To
This field describes the different C++ language elements that are legal targets for the specified attribute. For
instance, if an attribute specifies "class" in the Applies To field, this indicates that the attribute can only be
applied to a legal C++ class. If the attribute is applied to a member function of a class, a syntax error would
result.
For more information, see Attributes by Usage.
Repeatable
This field states whether the attribute can be repeatedly applied to the same target. The majority of attributes are
not repeatable.
Required Attributes
This field lists other attributes that need to be present (that is, applied to the same target) for the specified
attribute to function properly. It is uncommon for an attribute to have any entries for this field.
Invalid Attributes
This field lists other attributes that are incompatible with the specified attribute. It is uncommon for an attribute
to have any entries for this field.
In This Section
Attribute Programming FAQ
Attributes by Group
Attributes by Usage
Attributes Alphabetical Reference
Attributes by Group
7/27/2022 • 2 minutes to read • Edit Online
The C++ attributes are organized into the following functional groups.
IDL Attributes Enable the modification of the .idl file from a source code file
without the use of a wizard and without knowledge of the
structure and syntax of that file.
For information about how to define custom attributes for your .NET Framework application, see User-Defined
Attributes.
See also
C++ Attributes for COM and .NET
Attributes by Usage
Attributes Alphabetical Reference
COM Attributes
7/27/2022 • 2 minutes to read • Edit Online
The COM attributes inject code to support numerous areas of COM development and .NET Framework common
language runtime development. These areas range from custom interface implementation and support of
existing interfaces to supporting stock properties, methods, and events. In addition, support can be found for
composite and ActiveX control implementation.
See also
Attributes by Group
IDL Attributes
7/27/2022 • 6 minutes to read • Edit Online
async_uuid Specifies the UUID that directs the MIDL compiler to define
both synchronous and asynchronous versions of a COM
interface.
cpp_quote Emits the specified string, without the quote characters, into
the generated header file.
AT T RIB UT E DESC RIP T IO N
helpfile Sets the name of the Help file for a type library.
hidden Indicates that the item exists but should not be displayed in
a user-oriented browser.
idl_quote Allows you to use attributes or IDL constructs that are not
supported in the current version of Visual C++.
importlib Makes types that have already been compiled into another
type library available to the type library being created.
pointer_default Specifies the default pointer attribute for all pointers except
top-level pointers that appear in parameter lists.
pragma Emits the specified string, without the quote characters, into
the generated .idl file.
public Ensures that a typedef will go into the type library even if it
is not referenced from within the .idl file.
usesgetlasterror Tells the caller that if there is an error when calling that
function, the caller can then call GetLastError to retrieve
the error code.
See also
Attributes by Group
OLE DB Consumer Attributes
7/27/2022 • 2 minutes to read • Edit Online
The OLE DB consumer attributes inject code, based on the OLE DB Consumer Templates, to create a working OLE
DB consumer that performs tasks such as opening tables, executing commands, and accessing data.
See also
Attributes by Group
Compiler Attributes
7/27/2022 • 2 minutes to read • Edit Online
importidl Inserts the specified .idl file into the generated .idl file.
importlib Makes types that have already been compiled into another
type library available to the type library being created.
See also
Attributes by Group
Attributes by Usage
7/27/2022 • 2 minutes to read • Edit Online
This topic lists attributes according to the C++ language elements to which they apply.
If an attribute precedes an element that is not in the attribute's scope, the attribute block is treated as a
comment.
Data Member Attributes Applies to the data members in a class, coclass, or interface.
Typedef, Enum, Union, and Struct Attributes Applies to the C++ keywords.
Stand-Alone Attributes Operates more like a line of code but does not operate on a
C++ keyword. Stand-alone attribute statements require a
semicolon at the end of the line.
Module Attributes
The following attribute can only be applied to the module attribute.
Interface Attributes
The following attributes apply to the interface (or __interface) C++ keyword.
async_uuid Specifies the UUID that directs the MIDL compiler to define
both synchronous and asynchronous versions of a COM
interface.
AT T RIB UT E DESC RIP T IO N
helpfile Sets the name of the Help file for a type library.
hidden Indicates that the item exists but should not be displayed in
a user-oriented browser.
pointer_default Specifies the default pointer attribute for all pointers except
top-level pointers that appear in parameter lists.
See also
C++ Attributes for COM and .NET
Attributes by Group
Attributes Alphabetical Reference
Module Attributes
7/27/2022 • 2 minutes to read • Edit Online
See also
Attributes by Usage
Interface Attributes
7/27/2022 • 2 minutes to read • Edit Online
The following attributes apply to the interface (or __interface) C++ keyword.
async_uuid Specifies the UUID that directs the MIDL compiler to define
both synchronous and asynchronous versions of a COM
interface.
helpfile Sets the name of the Help file for a type library.
hidden Indicates that the item exists but should not be displayed in
a user-oriented browser.
pointer_default Specifies the default pointer attribute for all pointers except
top-level pointers that appear in parameter lists.
See also
Attributes by Usage
Class Attributes
7/27/2022 • 2 minutes to read • Edit Online
helpfile Sets the name of the Help file for a type library.
AT T RIB UT E DESC RIP T IO N
hidden Indicates that the item exists but should not be displayed in
a user-oriented browser.
See also
Attributes by Usage
Method Attributes
7/27/2022 • 2 minutes to read • Edit Online
helpfile Sets the name of the Help file for a type library.
hidden Indicates that the item exists but should not be displayed in
a user-oriented browser.
See also
Attributes by Usage
Parameter Attributes
7/27/2022 • 2 minutes to read • Edit Online
See also
Attributes by Usage
Data Member Attributes
7/27/2022 • 2 minutes to read • Edit Online
The following attributes apply to the data members in a class, coclass, or interface.
See also
Attributes by Usage
Typedef, Enum, Union, and Struct Attributes
7/27/2022 • 3 minutes to read • Edit Online
The following attributes apply to the typedef, struct, and enum C++ keywords.
typedef
AT T RIB UT E DESC RIP T IO N
helpfile Sets the name of the Help file for a type library.
public Ensures that a typedef will go into the type library even if it
is not referenced from within the .idl file.
enum
AT T RIB UT E DESC RIP T IO N
union
AT T RIB UT E DESC RIP T IO N
Nonencapsulated union
AT T RIB UT E DESC RIP T IO N
struct
AT T RIB UT E DESC RIP T IO N
hidden Indicates that the item exists but should not be displayed in
a user-oriented browser.
See also
Attributes by Usage
Array Attributes
7/27/2022 • 2 minutes to read • Edit Online
See also
Attributes by Usage
Stand-Alone Attributes
7/27/2022 • 2 minutes to read • Edit Online
A stand-alone attribute does not operate on a C++ keyword but is more like a line of code. Stand-alone attribute
statements require a semicolon at the end of the line.
cpp_quote Emits the specified string, without the quote characters, into
the generated header file.
idl_quote Allows you to use IDL constructs that are not supported in
the current version of Visual C++ and have them pass
through to the generated .idl file.
importidl Inserts the specified .idl file into the generated .idl file
importlib Makes types that have already been compiled into another
type library available to the type library being created.
pragma Emits the specified string, without the quote characters, into
the generated .idl file.
See also
Attributes by Usage
Custom Attributes (C++)
7/27/2022 • 2 minutes to read • Edit Online
A custom attribute is a strongly typed technique that allows the user to extend metadata. This topic deals with
using attributes: specifying parameters and targets.
For information on defining new custom attributes, see,
User-Defined Attributes
attribute (deprecated syntax).
See also
attribute
Custom Attributes (C++)
Attributes Alphabetical Reference
7/27/2022 • 6 minutes to read • Edit Online
async_uuid Specifies the UUID that directs the MIDL compiler to define
both synchronous and asynchronous versions of a COM
interface.
cpp_quote Emits the specified string, without the quote characters, into
the generated header file.
helpfile Sets the name of the Help file for a type library.
hidden Indicates that the item exists but should not be displayed in
a user-oriented browser.
idl_quote Allows you to use attributes or IDL constructs that are not
supported in the current version of Visual C++.
importidl Inserts the specified .idl file into the generated .idl file.
importlib Makes types that have already been compiled into another
type library available to the type library being created.
pointer_default Specifies the default pointer attribute for all pointers except
top-level pointers that appear in parameter lists.
pragma Emits the specified string, without the quote characters, into
the generated .idl file.
public Ensures that a typedef will go into the type library even if it
is not referenced from within the .idl file.
usesgetlasterror Tells the caller that if there is an error when calling that
function, the caller can then call GetLastError to retrieve
the error code.
See also
C++ Attributes for COM and .NET
Attributes by Group
Attributes by Usage
aggregatable
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ aggregatable(value) ]
Parameters
value
(Optional) A parameter to indicate when the COM object can be aggregated:
never The COM object cannot be aggregated.
allowed The COM object can be created directly or it can be aggregated. This is the default.
always The COM object cannot be created directly and can only be aggregated. When you call
CoCreateInstance for this object, you must specify the aggregating object's IUnknown interface (the
controlling IUnknown ).
Remarks
The aggregatable C++ attribute has the same functionality as the aggregatable MIDL attribute. This means
that the compiler will pass the aggregatable attribute through to the generated .idl file.
This attribute requires that the coclass, progid, or vi_progid attribute (or another attribute that implies one of
these) also be applied to the same element. If any single attribute is used, the other two are automatically
applied. For example, if progid is applied, vi_progid and coclass are also applied.
ATL Projects
If this attribute is used within a project that uses ATL, the behavior of the attribute changes. In addition to the
previously described behavior, the attribute also adds one of the following macros to the target class:
PA RA M ET ER VA L UE IN SERT ED M A C RO
Never DECLARE_NOT_AGGREGATABLE
Allowed DECLARE_POLY_AGGREGATABLE
Always DECLARE_ONLY_AGGREGATABLE
Example
// cpp_attr_ref_aggregatable.cpp
// compile with: /LD
#define _ATL_ATTRIBUTES
#include "atlbase.h"
#include "atlcom.h"
[module(name="MyModule")];
[ coclass, aggregatable(allowed),
uuid("1a8369cc-1c91-42c4-befa-5a5d8c9d2529")]
class CMyClass {};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Class Attributes
Typedef, Enum, Union, and Struct Attributes
Aggregation
aggregates
7/27/2022 • 2 minutes to read • Edit Online
Indicates that the object aggregates the object specified by the CLSID.
Syntax
[ aggregates(clsid, variable_name) ]
Parameters
clsid
Specifies the CLSID of the aggregatable object.
variable_name
The name of the variable that is to be inserted. This variable contains the IUnknown of the object being
aggregated.
Remarks
When applied to an object, the aggregates C++ attribute implements an outer wrapper for the object being
aggregated (specified by clsid ).
This attribute requires that the coclass, progid, or vi_progid attribute (or another attribute that implies one of
these) also be applied to the same element. If any single attribute is used, the other two are automatically
applied. For example, if progid is applied, vi_progid and coclass are also applied.
ATL Projects
If this attribute is used within a project that uses ATL, the behavior of the attribute changes. First, the following
entry is added to the COM map of the target object:
COM_INTERFACE_ENTRY_AUTOAGGREGATE_BLIND(_m_spAttrXXX, clsid)
Example
// cpp_attr_ref_aggregates.cpp
// compile with: /LD
#define _ATL_ATTRIBUTES
#include "atlbase.h"
#include "atlcom.h"
// requires 'aggregatable.dll'
// see aggregatable attribute to create 'aggregatable.dll'
class DECLSPEC_UUID("1a8369cc-1c91-42c4-befa-5a5d8c9d2529") CMyClass;
[module (name="MYObject")];
[object, uuid("ab006d85-e754-47c5-9ef4-2744ff32a20c")]
__interface IObject
{
};
[ coclass, aggregates(__uuidof(CMyClass)),
uuid("91cb2c06-8931-432a-baac-206e55c4edfb")]
struct CObject : IObject
{
int i;
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable Yes
For more information about the attribute contexts, see Attribute Contexts.
See also
COM Attributes
Class Attributes
Typedef, Enum, Union, and Struct Attributes
Aggregation
Aggregatable
COM_INTERFACE_ENTRY_AUTOAGGREGATE_BLIND
appobject
7/27/2022 • 2 minutes to read • Edit Online
Identifies the coclass as an application object, which is associated with a full .exe application, and indicates that
the functions and properties of the coclass are globally available in this type library.
Syntax
[appobject]
Remarks
The appobject C++ attribute has the same functionality as the appobject MIDL attribute.
Example
The following code shows a simple class definition preceded by an attribute block that includes appobject :
// cpp_attr_ref_appobject.cpp
// compile with: /LD
#include <windows.h>
[module(name="MyLib", uuid="f1ce17f0-a5df-4d26-95f6-0a122197ac5b")];
[object, uuid="905de6db-7a12-45ab-9f8b-b39f5112f010"]
__interface ICustom {};
[coclass, appobject,uuid="00395340-745f-4b69-bd58-e2921452b9fc"]
class A : public ICustom {
int i;
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Class Attributes
Typedef, Enum, Union, and Struct Attributes
async_uuid
7/27/2022 • 2 minutes to read • Edit Online
Specifies the UUID that directs the MIDL compiler to define both synchronous and asynchronous versions of a
COM interface.
Syntax
[async_uuid (uuid)]
Parameters
uuid
A UUID that identifies the version of the interface.
Remarks
The async_uuid C++ attribute has the same functionality as the async_uuid MIDL attribute.
Example
// cpp_attr_ref_async_uuid.cpp
// compile with: /LD
#include <Windows.h>
[module(name="Test")];
[object, uuid("9e66a290-4365-11d2-a997-00c04fa37ddb"),
async_uuid("e8583106-38fd-487e-912e-4fc8645c677e")]
__interface ICustom {
HRESULT Custom([in] long l, [out, retval] long *pLong);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to interface
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Interface Attributes
attribute
7/27/2022 • 2 minutes to read • Edit Online
NOTE
The attribute attribute is now deprecated. Use the common language runtime attribute System.Attribute to directly
to create user-defined attributes. For more information, see User-Defined Attributes.
See also
Attributes Alphabetical Reference
bindable
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[bindable]
Remarks
The bindable C++ attribute has the same functionality as the bindable MIDL attribute. You can use it on
properties defined with the propget, propput, or propputref attributes, or you can manually define a bindable
method.
The following MFC samples show the use of bindable :
Controls Samples: MFC-Based ActiveX Controls
CIRC Sample: ActiveX Control
TESTHELP Sample: ActiveX Control with Tooltips and Help
Example
The following code shows how you can use bindable on a property:
// cpp_attr_ref_bindable.cpp
// compile with: /LD
#include <windows.h>
[
uuid("479B29E3-9A2C-11D0-B696-00A0C903487A"), dispinterface, helpstring("property demo Interface")
]
__interface IPropDemo : IDispatch {
[propget, id(1), bindable, displaybind, defaultbind, requestedit] HRESULT P1([out, retval] long *nSize);
[propput, id(1), bindable, displaybind, defaultbind, requestedit] HRESULT P1([in] long nSize);
[id(3), bindable, propget] HRESULT Object([out, retval] IDispatch **ppObj);
[id(3), bindable, propputref] HRESULT Object([in] IDispatch* pObj);
[id(-552), helpstring("method AboutBox")] HRESULT AboutBox();
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
AT T RIB UT E C O N T EXT VA L UE
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Method Attributes
defaultbind
displaybind
immediatebind
requestedit
call_as
7/27/2022 • 2 minutes to read • Edit Online
Enables a local function to be mapped to a remote function so that when the remote function is called, the local
function is invoked.
Syntax
[ call_as(function) ]
Parameters
function
The local function that you want to be called when a remote function is invoked.
Remarks
The call_as C++ attribute has the same functionality as the call_as MIDL attribute.
Example
The following code shows how you can use call_as to map a nonremotable function ( f1 ) to a remotable
function ( Remf1 ):
// cpp_attr_ref_call_as.cpp
// compile with: /LD
#include "unknwn.h"
[module(name="MyLib")];
[dual, uuid("00000000-0000-0000-0000-000000000001")]
__interface IMInterface {
[local] HRESULT f1 ( int i );
[call_as(f1)] HRESULT Remf1 ( int i );
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Method Attributes
local
case (C++)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ case(value) ]
Parameters
value
A possible input value for which you want to provide processing. The type of value can be one of the following
types:
int
char
boolean
enum
Remarks
The case C++ attribute has the same functionality as the case MIDL attribute. This attribute is only used with
the switch_type attribute.
Example
The following code shows a use of the case attribute:
// cpp_attr_ref_case.cpp
// compile with: /LD
#include <unknwn.h>
[export]
struct SizedValue2 {
[switch_type(char), switch_is(kind)] union {
[case(1), string]
wchar_t* wval;
[default, string]
char* val;
};
char kind;
};
[module(name="ATLFIRELib")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
Class Attributes
coclass
7/27/2022 • 3 minutes to read • Edit Online
Syntax
[coclass]
Remarks
The coclass C++ attribute places a coclass construct in the generated .idl file.
When defining a coclass, you can also specify the uuid, version, threading, vi_progid, and progid attributes. If any
one of them is not specified, it will be generated.
If two header files contain classes with the coclass attribute and don't specify a GUID, the compiler will use the
same GUID for both classes, and that will result in a MIDL error. Therefore, you should use the uuid attribute
when you use coclass .
ATL Projects
When this attribute precedes a class or structure definition in an ATL project, it:
Injects code or data to support auto registration for the object.
Injects code or data to support a COM class factory for the object.
Injects code or data to implement IUnknown and make the object a COM-creatable object.
Specifically, the following base classes are added to the target object:
CComCoClass Class provides the default class factory and aggregation model for the object.
CComObjectRootEx Class has a template based on the threading model class specified by the threading
attribute. If the threading attribute is not specified, the default threading model is apartment.
IProvideClassInfo2Impl is added if the noncreatable attribute is not specified for the target object.
Finally, any dual interface that is not defined using embedded IDL is replaced with the corresponding
IDispatchImpl class. If the dual interface is defined in embedded IDL, the particular interface in the base list is not
modified.
The coclass attribute also makes the following functions available via injected code, or in the case of
GetObjectCLSID , as a static method in the base class CComCoClass :
Example
The following code shows how to use the coclass attribute:
// cpp_attr_ref_coclass1.cpp
// compile with: /LD
#include "unknwn.h"
[module(name="MyLib")];
[ object, uuid("00000000-0000-0000-0000-000000000001") ]
__interface I {
HRESULT func();
};
The following sample shows how to override the default implementation of a function that appears in the code
injected by the coclass attribute. See /Fx for more information on viewing injected code. Any base classes or
interfaces that you use for a class will be appear in the injected code. Further, if a class is included by default in
the injected code and you explicitly specify that class as a base for your coclass, the attribute provider will use
the form specified in your code.
// cpp_attr_ref_coclass2.cpp
// compile with: /LD
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
#include <atlplus.h>
[module(name="MyLib")];
[object, uuid("00000000-0000-0000-0000-000000000000")]
__interface bb {};
[coclass, uuid("00000000-0000-0000-0000-000000000001")]
class CMyClass : public bb {
public:
// by adding the definition of UpdateRegistry to your code, // the function will not be included in the
injected code
static HRESULT WINAPI UpdateRegistry(BOOL bRegister) {
// you can add to the default implementation
CRegistryVirtualMachine rvm;
HRESULT hr;
if (FAILED(hr = rvm.AddStandardReplacements()))
return hr;
rvm.AddReplacement(_T("FriendlyName"), GetObjectFriendlyName());
return rvm.VMUpdateRegistry(GetOpCodes(), GetOpcodeStringVals(), GetOpcodeDWORDVals(),
GetOpcodeBinaryVals(), bRegister);
}
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
COM Attributes
Class Attributes
Typedef, Enum, Union, and Struct Attributes
appobject
com_interface_entry (C++)
7/27/2022 • 2 minutes to read • Edit Online
Adds an interface entry into the COM map of the target class.
Syntax
[ com_interface_entry(
com_interface_entry) ]
Parameters
com_interface_entry
A string containing the actual text of the entry. For a list of possible values, see COM_INTERFACE_ENTRY Macros.
Remarks
The com_interface_entr y C++ attribute inserts the unabridged contents of a character string into the COM
interface map of the target object. If the attribute is applied once to the target object, the entry is inserted into
the beginning of the existing interface map. If the attribute is applied repeatedly to the same target object, the
entries are inserted at the beginning of the interface map in the order they are received.
This attribute requires that the coclass, progid, or vi_progid attribute (or another attribute that implies one of
these) also be applied to the same element. If any single attribute is used, the other two are automatically
applied. For example, if progid is applied, vi_progid and coclass are also applied.
Because the first usage of com_interface_entr y causes the new interface to be inserted at the beginning of the
interface map, it must be one of the following COM_INTERFACE_ENTRY types:
COM_INTERFACE_ENTRY
COM_INTERFACE_ENTRY_IID
COM_INTERFACE_ENTRY2
COM_INTERFACE_ENTRY2_IID
Additional usages of the com_interface_entr y attribute can use all supported COM_INTERFACE_ENTRY types.
This restriction is necessary because ATL uses the first entry in the interface map as the identity IUnknown ;
therefore, the entry must be a valid interface. For example, the following code sample is invalid because the first
entry in the interface map does not specify an actual COM interface.
[ coclass, com_interface_entry =
"COM_INTERFACE_ENTRY_NOINTERFACE(IDebugTest)"
]
class CMyClass
{
};
Example
The following code adds two entries to the existing COM interface map of CMyBaseClass . The first is a standard
interface, and the second hides the IDebugTest interface.
// cpp_attr_ref_com_interface_entry.cpp
// compile with: /LD
#define _ATL_ATTRIBUTES
#include "atlbase.h"
#include "atlcom.h"
[ object,
uuid("7dbebed3-d636-4917-af62-c767a720a5b9")]
__interface IDebugTest{};
[ object,
uuid("2875ceac-f94b-4087-8e13-d13dc167fcfc")]
__interface IMyClass{};
[ coclass,
com_interface_entry ("COM_INTERFACE_ENTRY (IMyClass)"),
com_interface_entry ("COM_INTERFACE_ENTRY_NOINTERFACE(IDebugTest)"),
uuid("b85f8626-e76e-4775-b6a0-4826a9e94af2")
]
BEGIN_COM_MAP(CMyClass)
COM_INTERFACE_ENTRY (IMyClass)
COM_INTERFACE_ENTRY_NOINTERFACE(IDebugTest)
COM_INTERFACE_ENTRY(IMyClass)
COM_INTERFACE_ENTRY2(IDispatch, IMyClass)
COM_INTERFACE_ENTRY(IDebugTest)
COM_INTERFACE_ENTRY(IProvideClassInfo)
END_COM_MAP()
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable Yes
For more information about the attribute contexts, see Attribute Contexts.
See also
COM Attributes
Class Attributes
Typedef, Enum, Union, and Struct Attributes
control
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[control]
Remarks
The control attribute implies the coclass attribute. The control C++ attribute has the same functionality as the
control MIDL attribute.
Example
// cpp_attr_ref_control.cpp
// compile with: /LD
#include <windows.h>
[module(name="Test", control=true)];
[object, uuid("9e66a290-4365-11d2-a997-00c04fa37ddb")]
__interface ICustom {
HRESULT Custom([in] long l, [out, retval] long *pLong);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Class Attributes
Typedef, Enum, Union, and Struct Attributes
cpp_quote
7/27/2022 • 2 minutes to read • Edit Online
Emits the specified string, without the quote characters, into the generated .idl file.
Syntax
[ cpp_quote("statement") ];
Parameters
statement
A C instruction.
Remarks
The cpp_quote C++ attribute is useful if you want to put a preprocessor directive in an .idl file.
You can also use cpp_quote and generate an .h file as part of the MIDL compilation. For example, if you have a
C++ header file that uses C++ IDL attributes but cannot use this file for some task, then you can compile it to
create a MIDL-generated .h file, which you should be able to use.
The cpp_quote attribute has the same functionality as the cpp_quote MIDL attribute.
Example
See the example for dual for an example use how to use cpp_quote .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Stand-Alone Attributes
custom (C++)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ custom(
uuid,
value
) ];
Parameters
uuid
A unique ID.
value
A value that can be put into a variant.
Remarks
The custom C++ attribute will cause information to be placed into the type library. You will need a tool that
reads the custom value from type library.
The custom attribute has the same functionality as the custom MIDL attribute.
Requirements
Attribute Context
Applies to : Non-COM interface , idl_module methods, interface members, interface parameters, typedef ,
class , enum , union , and struct types.
Repeatable : Yes.
Required attributes : coclass (when used on class).
Invalid attributes : None.
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Stand-Alone Attributes
Typedef, Enum, Union, and Struct Attributes
Parameter Attributes
Method Attributes
Class Attributes
Interface Attributes
db_accessor
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ db_accessor(num, auto) ]
Parameters
num
Specifies the accessor number (a zero-based integer index). You must specify accessor numbers in increasing
order, using integers or defined values.
auto
A Boolean value that specifies whether the accessor is automatically retrieved (TRUE) or not retrieved (FALSE).
Remarks
db_accessor defines the underlying OLE DB accessor for subsequent db_column and db_param attributes
within the same class or function. db_accessor is usable at member level and is used to group db_column
attributes that participate in OLE DB IAccessor -based binding. It is used in conjunction with either the
db_table or db_command attributes. Calling this attribute is similar to calling the BEGIN_ACCESSOR and
END_ACCESSOR macros.
db_accessor generates a rowset and binds it to the corresponding accessor maps. If you do not call
db_accessor , accessor 0 will automatically be generated, and all column bindings will be mapped to this
accessor block.
db_accessor groups database column bindings into one or more accessors. For a discussion of the scenarios in
which you need to use multiple accessors, see Using Multiple Accessors on a Rowset. Also see "User Record
Support for Multiple Accessors" in User Records.
When the consumer attribute provider applies this attribute to a class, the compiler will rename the class to
_YourClassNameAccessor, where YourClassName is the name you gave the class, and the compiler will also
create a class called YourClassName, which derives from _YourClassNameAccessor. In Class View, you will see
both classes.
Example
The following example uses db_accessor to group columns in the Orders table from the Northwind database
into two accessors. Accessor 0 is an automatic accessor, and accessor 1 is not.
// cpp_attr_ref_db_accessor.cpp
// compile with: /LD /link /OPT:NOREF
#define _ATL_ATTRIBUTES
#include <atlbase.h>
#include <atldbcli.h>
[ db_accessor(1, FALSE) ];
[ db_column("8") ] CURRENCY m_Freight;
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
OLE DB Consumer Attributes
db_column
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ db_column(ordinal, dbtype, precision, scale, status, length) ]
Parameters
ordinal
The ordinal column number ( DBCOLUMNINFO ordinal) or column name (ANSI or Unicode string) corresponding to
a field in the rowset to which to bind data. If you use numbers, you can skip consecutive ordinals (for example: 1,
2, 3, 5). The name may contain spaces if the OLE DB provider you use supports it. For example, you can use
either of the following formats:
dbtype
(Optional) An OLE DB Type Indicator for the column entry.
precision
(Optional) The precision to be used for the column entry. For details, see the description of the bPrecision
element of the DBBINDING structure
scale
(Optional) The scale to be used for the column entry. For details, see the description of bScale element of the
DBBINDING structure
status
(Optional) A member variable used to hold the status of this column. The status indicates whether the column
value is a data value or some other value, such as NULL. For possible values, see Status in the OLE DB
Programmer's Reference.
length
(Optional) A member variable used to hold the size of the column in bytes.
Remarks
db_column binds the specified table column to a variable in the rowset. It delimits member data that can
participate in OLE DB IAccessor -based binding. This attribute sets up the column map normally defined using
the OLE DB consumer macros BEGIN_COLUMN_MAP, END_COLUMN_MAP, and COLUMN_ENTRY. These
manipulate the OLE DB DBBINDING structure to bind the specified column. Each member you mark with the
db_column attribute will occupy one entry in the column map in the form of a column entry. Therefore, you
call this attribute where you would put the column map, that is, in the command or table class.
Use db_column in conjunction with either the db_table or db_command attributes.
When the consumer attribute provider applies this attribute to a class, the compiler will rename the class to
_YourClassNameAccessor, where YourClassName is the name you gave the class, and the compiler will also
create a class called YourClassName, which derives from _YourClassNameAccessor. In Class View, you will see
both classes.
For an example of this attribute used in an application, see MultiRead.
Examples
This sample binds a column in a table to a long data member and specifies status and length fields.
// db_column_1.cpp
// compile with: /LD
#include <atlbase.h>
#include <atlplus.h>
#include <atldbcli.h>
This sample binds four columns to a long , a character string, a timestamp, and a DB_NUMERIC integer, in that
order.
// db_column_2.cpp
// compile with: /LD
#include <atlbase.h>
#include <atlplus.h>
#include <atldbcli.h>
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
OLE DB Consumer Attributes
Class Attributes
db_command
7/27/2022 • 5 minutes to read • Edit Online
Syntax
[ db_command(command, name, source_name, hresult, bindings, bulk_fetch) ]
Parameters
command
A command string containing the text of an OLE DB command. A simple example is:
where:
( marks the start of the data binding block.
bindtype is one of the following case-insensitive strings:
[db_column] binds each of the member variables to a column in a rowset.
[bindto] (same as [db_column] ).
[in] binds member variables as input parameters.
[out] binds member variables as output parameters.
[in,out] binds member variables as input/output parameters.
szVarN, nVarN resolve to member variables within the current scope.
) marks the end of the data binding block.
If the command string contains one or more specifiers such as [in] , [out] , or [in/out] , db_command builds a
parameter map.
If the command string contains one or more parameters such as [db_column] or [bindto] , then db_command
generates both a rowset and an accessor map to service these bound variables. For more information, see
db_accessor .
NOTE
bindtype syntax and the bindings parameter are not valid when using db_command at the class level.
Here are some examples of binding parameter blocks. The following example binds the m_au_fname and
m_au_lname data members to the au_fname and au_lname columns, respectively, of the authors table in the
pubs database:
TCHAR m_au_fname[21];
TCHAR m_au_lname[41];
TCHAR m_state[3] = 'CA';
name
(Optional) The name of the handle you use to work with the rowset. If you specify name , db_command generates
a class with the specified name , which can be used to traverse the rowset or to execute multiple action queries. If
you don't specify name , it will not be possible to return more than one row of results to the user.
source_name
(Optional) The CSession variable or instance of a class that has the db_source attribute applied to it on which
the command executes. See db_source .
db_command checks to ensure that the variable used for source_name is valid, so the specified variable should be
in function or global scope.
hresult
(Optional) Identifies the variable that will receive the HRESULT of this database command. If the variable doesn't
exist, it will be automatically injected by the attribute.
bindings
(Optional) Allows you to separate the binding parameters from the OLE DB command.
If you specify a value for bindings , db_command parses the associated value and doesn't parse the bindtype
parameter. This usage allows you to use OLE DB provider syntax. To disable parsing without binding parameters,
specify Bindings="" .
If you don't specify a value for bindings , db_command parses the binding parameter block. It looks for ' ( ',
followed by a bindtype in brackets, followed by one or more previously declared C++ member variables,
followed by ' ) '. It strips all text between the parentheses from the resulting command. These parameters are
used to construct column and parameter bindings for this command.
bulk_fetch
(Optional) An integer value that specifies the number of rows to fetch.
The default value is 1, which specifies single row fetching (the rowset will be of type CRowset ).
A value greater than 1 specifies bulk row fetching. Bulk row fetching refers to the ability of bulk rowsets to fetch
multiple row handles (the rowset will be of type CBulkRowset and will call SetRows with the specified number of
rows).
If bulk_fetch is less than one, SetRows will return zero.
Remarks
db_command creates a CCommand object, which is used by an OLE DB consumer to execute a command.
You can use db_command with either class or function scope; the main difference is the scope of the CCommand
object. With function scope, data such as bindings terminate at function end. Both class and function scope
usages involve the OLE DB Consumer Template class CCommand<> , but the template arguments differ for the
function and class cases. In the function case, bindings will be made to an Accessor that comprises local
variables, while the class usage will infer a CAccessor -derived class as the argument. When used as a class
attribute, db_command works together with db_column .
db_command can be used to execute commands that don't return a result set.
When the consumer attribute provider applies this attribute to a class, the compiler renames the class to
_[YourClassName]Accessor , where [YourClassName] is the name you gave the class. The compiler also creates a
class called [YourClassName] , which derives from _[YourClassName]Accessor . In Class View, you'll see both
classes.
Examples
This sample defines a command that selects the first and last names from a table where the state column
matches 'CA'. db_command creates and reads a rowset on which you can call wizard-generated functions such as
OpenAll and CloseAll , as well as CRowset member functions such as MoveNext .
This code requires you to provide your own connection string that connects to the pubs database. For
information on how to provide a connection string in the development environment, see How to: Connect to a
database and browse existing objects and Add new connections.
Source file db_command.h :
// db_command.h
#include <atlbase.h>
#include <atlplus.h>
#include <atldbcli.h>
#pragma once
struct CAuthors {
// In order to fix several issues with some providers, the code below may bind
// columns in a different order than reported by the provider
DBSTATUS m_dwau_lnameStatus;
DBSTATUS m_dwau_fnameStatus;
DBLENGTH m_dwau_lnameLength;
DBLENGTH m_dwau_fnameLength;
// db_command.cpp
// compile with: /c
#include "db_command.h"
// Instantiate rowset
CAuthors rs;
rs.CloseAll();
CoUninitialize();
}
This sample uses db_source on a data source class CMySource , and db_command on command classes
CCommand1 and CCommand2 .
// db_command_2.cpp
// compile with: /c
#include <atlbase.h>
#include <atlplus.h>
#include <atldbcli.h>
// class usage for both db_source and db_command
int main() {
CMySource s;
HRESULT hr = s.OpenDataSource();
if (SUCCEEDED(hr)) {
CCommand1 c1;
hr = c1.Open(s);
CCommand2 c2;
hr = c2.Open(s);
}
s.CloseDataSource();
}
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute contexts.
See also
OLE DB consumer attributes
Stand-alone attributes
db_param
7/27/2022 • 2 minutes to read • Edit Online
Associates the specified member variable with an input or output parameter and delimits the variable.
Syntax
[ db_param(ordinal, paramtype="DBPARAMIO_INPUT", dbtype, precision, scale, status, length) ]
Parameters
ordinal
The column number (DBCOLUMNINFO ordinal) corresponding to a field in the rowset to which to bind data.
paramtype
(Optional) The type to set for the parameter. Providers support only parameter I/O types that are supported by
the underlying data source. The type is a combination of one or more DBPARAMIOENUM values:
DBPARAMIO_INPUT An input parameter.
DBPARAMIO_OUTPUT An output parameter.
DBPARAMIO_NOTPARAM The accessor has no parameters. Setting eParamIO to this value in row
accessors reminds the user that parameters are ignored.
dbtype
(Optional) An OLE DB Type Indicator for the column entry.
precision
(Optional) The precision to be used for the column entry. For details, see the description of bPrecision element
of the DBBINDING structure
scale
(Optional) The scale to be used for the column entry. For details, see the description of bScale element of the
DBBINDING structure
status
(Optional) A member variable used to hold the status of this column. The status indicates whether the column
value is a data value or some other value, such as NULL. For possible values, see Status in the OLE DB
Programmer's Reference.
length
(Optional) A member variable used to hold the size of the column in bytes.
Remarks
db_param defines parameters that you use in commands; therefore you use it with db_command . For example,
you can use db_param to bind parameters in SQL queries or stored procedures. Parameters in a stored
procedure are denoted by question marks (?), and you should bind the data members in the order in which the
parameters appear.
db_param delimits member data that can participate in OLE DB ICommandWithParameters -based binding. It sets
the parameter type (input or output), OLE DB type, precision, scale, status, and length for the specified
parameter. This attribute inserts the OLE DB consumer macros BEGIN_PARAM_MAP ... END_PARAM_MAP. Each
member you mark with the db_param attribute will occupy one entry in the map in the form of a
COLUMN_ENTRY.
db_param is used in conjunction with either the db_table or db_command attributes.
When the consumer attribute provider applies this attribute to a class, the compiler will rename the class to
_YourClassNameAccessor, where YourClassName is the name you gave the class, and the compiler will also
create a class called YourClassName, which derives from _YourClassNameAccessor. In Class View, you will see
both classes.
Example
The following example creates a command class based on the SalesbyYear stored procedure in the Northwind
database. It associates the first parameter in the stored procedure with the m_RETURN_VALUE variable, and defines
it as an output parameter. It associates the last two (input) parameters with m_Beginning_Date and
m_Ending_Date .
The following example associates the nOutput variable with an output parameter.
// db_param.cpp
// compile with: /LD
#include <atlbase.h>
#include <atlplus.h>
#include <atldbcli.h>
[ db_source(L"my_connection_string"),
db_command(L"{ ? = CALL dbo.\"Sales by Year\"(?,?) }")
]
struct CSalesbyYear {
DBSTATUS m_dwShippedDateStatus;
DBSTATUS m_dwOrderIDStatus;
DBSTATUS m_dwSubtotalStatus;
DBSTATUS m_dwYearStatus;
DBLENGTH m_dwShippedDateLength;
DBLENGTH m_dwOrderIDLength;
DBLENGTH m_dwSubtotalLength;
DBLENGTH m_dwYearLength;
// Bind columns
[ db_column("1", status="m_dwShippedDateStatus", length="m_dwShippedDateLength") ] DBTIMESTAMP
m_ShippedDate;
[ db_column("2", status="m_dwOrderIDStatus", length="m_dwOrderIDLength") ] LONG m_OrderID;
[ db_column("3", status="m_dwSubtotalStatus", length="m_dwSubtotalLength") ] CURRENCY m_Subtotal;
[ db_column("4", status="m_dwYearStatus", length="m_dwYearLength") ] TCHAR m_Year[31];
// Bind parameters
[ db_param("1", paramtype="DBPARAMIO_OUTPUT") ] LONG m_RETURN_VALUE;
[ db_param("2", paramtype="DBPARAMIO_INPUT") ] DBTIMESTAMP m_Beginning_Date;
[ db_param("3", paramtype="DBPARAMIO_INPUT") ] DBTIMESTAMP m_Ending_Date;
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
OLE DB Consumer Attributes
db_source
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ db_source(db_source, name, hresult) ]
Parameters
db_source
The connection string used to connect to the data source. For the format of the connection string, see
Connection Strings and Data Links in the Microsoft Data Access Components (MDAC) SDK.
name
(Optional) When you use db_source on a class, name is an instance of a data source object that has the
db_source attribute applied to it (see example 1). When you use db_source inline in a method
implementation, name is a variable (local to the method) that can be used to access the data source (see
example 2). You pass this name to the source_name parameter of db_command to associate the data source with
a command.
hresult
(Optional) Identifies the variable that will receive the HRESULT of this database command. If the variable does
not exist, it will be automatically injected by the attribute.
Remarks
db_source creates a CDataSource and a CSession object, which together represent a connection with an OLE
DB consumer data source.
When you use db_source on a class, the CSession object becomes a member of the class.
When you use db_source in a method, the injected code will be executed within method scope, and the
CSession object is created as a local variable.
db_source adds data source properties to a class or within a method. It is used in conjunction with db_command
(which takes the db_source name parameter as its source_name parameter).
When the consumer attribute provider applies this attribute to a class, the compiler will rename the class to
_YourClassNameAccessor, where YourClassName is the name you gave the class, and the compiler will also
create a class called YourClassName, which derives from _YourClassNameAccessor. In Class View, you will see
both classes.
For an example of this attribute used in an application, see MultiRead.
Example
This sample calls db_source on a class to create a connection to the data source ds using the Northwind
database. ds is a handle for the data source, which can be used internally to the CMyCommand class.
// db_source_1.cpp
// compile with: /LD
#include <atlbase.h>
#include <atlplus.h>
#include <atldbcli.h>
[
db_source(L"my_connection_string", name="ds"),
db_command(L"select * from Products")
]
class CMyCommand {};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
OLE DB Consumer Attributes
db_table
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ db_table(db_table, name, source_name, hresult) ]
Parameters
db_table
A string specifying the name of a database table (such as "Products").
name
(Optional) The name of the handle you use to work with the table. You must specify this parameter if you want
to return more than one row of results. db_table generates a variable with the specified name that can be used
to traverse the rowset or execute multiple action queries.
source_name
(Optional) The CSession variable or instance of a class that has the db_source attribute applied to it on which
the command executes. See db_source.
hresult
(Optional) Identifies the variable that will receive the HRESULT of this database command. If the variable does
not exist, it will be automatically injected by the attribute.
Remarks
db_table creates a CTable object, which is used by an OLE DB consumer to open a table. You can use this
attribute only at the class level; you cannot use it inline. Use db_column to bind table columns to variables; use
db_param to delimit (set the parameter type and so on) of parameters.
When the consumer attribute provider applies this attribute to a class, the compiler will rename the class to
_YourClassNameAccessor, where YourClassName is the name you gave the class, and the compiler will also
create a class called YourClassName, which derives from _YourClassNameAccessor. In Class View, you will see
both classes.
Example
The following example opens the Products table for use by CProducts .
// db_table.cpp
// compile with: /LD
#include <atlbase.h>
#include <atlplus.h>
#include <atldbcli.h>
[ db_table(L"dbo.Products") ]
class CProducts {
[ db_column("1") ] LONG m_ProductID;
};
For an example of this attribute used in an application, see MultiRead.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
OLE DB Consumer Attributes
default (C++)
7/27/2022 • 2 minutes to read • Edit Online
Indicates that the custom or dispinterface defined within a coclass represents the default programmability
interface.
Syntax
[ default(interface1, interface2) ]
Parameters
interface1
The default interface that will be made available to scripting environments that create an object based on the
class defined with the default attribute.
If no default interface is specified, the first occurrence of a nonsource interface is used as the default.
interface2
(Optional) The default source interface. You must also specify this interface with the source attribute.
If no default source interface is specified, the first source interface is used as the default.
Remarks
The default C++ attribute has the same functionality as the default MIDL attribute. The default attribute is
also used with the case attribute.
Example
The following code shows how default is used on the definition of a coclass to specify ICustomDispatch as the
default programmability interface:
// cpp_attr_ref_default.cpp
// compile with: /LD
#include "windows.h"
[module(name="MyLibrary")];
[object, uuid("9E66A290-4365-11D2-A997-00C04FA37DDB")]
__interface ICustom {
HRESULT Custom([in] long l, [out, retval] long *pLong);
};
[dual, uuid("9E66A291-4365-11D2-A997-00C04FA37DDB")]
__interface IDual {
HRESULT Dual([in] long l, [out, retval] long *pLong);
};
[object, uuid("9E66A293-4365-11D2-A997-00C04FA37DDB")]
__interface ICustomDispatch : public IDispatch {
HRESULT Dispatch([in] long l, [out, retval] long *pLong);
};
int main() {
#if 0 // Can't instantiate without implementations of IUnknown/IDispatch
CClass *pClass = new CClass;
long llong;
pClass->custom(1, &llong);
pClass->dual(1, &llong);
pClass->dispinterface(1, &llong);
pClass->dispatch(1, &llong);
delete pClass;
#endif
return(0);
}
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Class Attributes
coclass
defaultbind
7/27/2022 • 2 minutes to read • Edit Online
Indicates the single, bindable property that best represents the object.
Syntax
[defaultbind]
Remarks
The defaultbind C++ attribute has the same functionality as the defaultbind MIDL attribute.
Example
See the example for bindable for an example of how to use defaultbind .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Method Attributes
Data Member Attributes
displaybind
immediatebind
requestedit
defaultcollelem
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[defaultcollelem]
Remarks
The defaultcollelem C++ attribute has the same functionality as the defaultcollelem MIDL attribute.
Example
The following code shows an interface method using the defaultcollelem attribute:
// cpp_attr_ref_defaultcollelem.cpp
// compile with: /LD
#include <unknwn.h>
[module(name="MyLib")];
[object, uuid("00000000-0000-0000-0000-000000000001")]
__interface IMyForm
{
[propget, id(1), bindable, defaultcollelem, displaybind, defaultbind, requestedit] HRESULT P1([out,
retval] long *nSize);
[propput, id(1), bindable, defaultcollelem, displaybind, defaultbind, requestedit] HRESULT P1([in] long
nSize);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Method Attributes
defaultvalue
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ defaultvalue= value ]
Parameters
value
The default value for the parameter.
Remarks
The defaultvalue C++ attribute has the same functionality as the defaultvalue MIDL attribute.
Example
The following code shows an interface method using the defaultvalue attribute:
// cpp_attr_ref_defaultvalue.cpp
// compile with: /LD
#include <windows.h>
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Parameter Attributes
out
retval
in
pointer_default
unique
defaultvtable
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ defaultvtable(interface) ]
Parameters
interface
The designated interface that you want to have the default vtable for the COM object.
Remarks
The defaultvtable C++ attribute has the same functionality as the defaultvtable MIDL attribute.
Example
The following code shows attributes on a class that use defaultvtable to specify a default interface:
// cpp_attr_ref_defaultvtable.cpp
// compile with: /LD
#include <unknwn.h>
[module(name="MyLib")];
[object, uuid("00000000-0000-0000-0000-000000000001")]
__interface IMyI1 {
HRESULT x();
};
[object, uuid("00000000-0000-0000-0000-000000000002")]
__interface IMyI2 {
HRESULT x();
};
[object, uuid("00000000-0000-0000-0000-000000000003")]
__interface IMyI3 {
HRESULT x();
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
AT T RIB UT E C O N T EXT VA L UE
See also
IDL Attributes
Class Attributes
dispinterface
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[dispinterface]
Remarks
When the dispinterface C++ attribute precedes an interface, it causes the interface to be placed inside the
library block in the generated .idl file.
Unless you specify a base class, a dispatch interface will derive from IDispatch . You must specify an id for the
members of a dispatch interface.
The usage example for dispinterface in the MIDL documentation:
dispinterface helloPro
{ interface hello; };
Example
See the example for bindable for an example of how to use dispinterface .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to interface
Repeatable No
See also
IDL Attributes
Attributes by Usage
uuid
dual
custom
object
__interface
displaybind
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[displaybind]
Remarks
The displaybind C++ attribute has the same functionality as the displaybind MIDL attribute.
Example
See the example for bindable for an example of how to use displaybind .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Method Attributes
Data Member Attributes
defaultbind
immediatebind
requestedit
dual
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[dual]
Remarks
When the dual C++ attribute precedes an interface, it causes the interface to be placed inside the library block
in the generated .idl file.
Example
The following code is an attribute block that uses dual before an interface definition:
// cpp_attr_ref_dual.cpp
// compile with: /LD
#include <windows.h>
[module(name="MyLibrary")];
[uuid("2F5F63F1-16DA-11d2-9E7B-00C04FB926DA"), dual]
[cpp_quote("#include file.h")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to interface
Repeatable No
Specifies whether all subsequent IDL attributes are processed and placed in the generated .idl file.
Syntax
[ emitidl(state, defaultimports=boolean) ];
Parameters
state
One of these possible values: true , false , forced , restricted , push , or pop .
If true , any IDL category attributes encountered in a source code file are placed in the generated .idl file.
This is the default setting for emitidl .
If false , any IDL category attributes encountered in a source code file are not placed in the generated
.idl file.
If restricted , allows IDL attributes to be in the file without a module attribute. The compiler does not
generate an .idl file.
If forced , overrides a subsequent restricted attribute, which requires a file to have a module attribute
if there are IDL attributes in the file.
pushlets you save the current emitidl settings to an internal emitidl stack, and pop lets you set
emitidl to whatever value is at the top of the internal emitidl stack.
defaultimports= boolean (optional)
If boolean is true , docobj.idl is imported into the generated .idl file. Also, if an .idl file with the same
name as an .h file that you #include into your source code is found in the same directory as the .h file,
then the generated .idl file contains an import statement for that .idl file.
If boolean is false , docobj.idl is not imported into the generated .idl file. You must explicitly import .idl
files with import.
Remarks
After the emitidl C++ attribute is encountered in a source code file, IDL category attributes are placed in the
generated .idl file. If there is no emitidl attribute, IDL attributes in the source code file are output to the
generated .idl file.
It is possible to have multiple emitidl attributes in a source code file. If [emitidl(false)]; is encountered in a
file without a subsequent [emitidl(true)]; , then no attributes are processed into the generated .idl file.
Each time the compiler encounters a new file, emitidl is implicitly set to true .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
See also
Compiler Attributes
Stand-Alone Attributes
entry
7/27/2022 • 2 minutes to read • Edit Online
Specifies an exported function or constant in a module by identifying the entry point in the DLL.
Syntax
[ entry(id) ]
Parameters
id
The ID of the entry point.
Remarks
The entr y C++ attribute has the same functionality as the entry MIDL attribute.
Example
See the example for idl_module for an example use of entr y .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
event_receiver attribute
7/27/2022 • 2 minutes to read • Edit Online
NOTE
Event attributes in native C++ are incompatible with Standard C++. They don't compile when you specify /permissive-
conformance mode.
Syntax
[ event_receiver(type
[, layout_dependent=false]) ]
Parameters
type
An enumeration of one of the following values:
native for unmanaged C/C++ code (default for native classes).
com for COM code. This value requires that you include these header files:
#define _ATL_ATTRIBUTES
#include <atlbase.h>
#include <atlcom.h>
layout_dependent
Specify layout_dependent only if type =com . layout_dependent is a Boolean:
true means that the signature of the delegates in the event receiver must exactly match the ones they're
hooked to in the event source. The event receiver handler names must match the names specified in the
relevant event source interface. Use coclass when layout_dependent is true . It's slightly more efficient
to specify true .
false (default) means that the calling convention and storage class ( virtual , static , and others) don't
have to match the event method and the handlers. The handler names also don't need to match the event
source interface method names.
Remarks
The event_receiver C++ attribute specifies that the class or structure to which it's applied will be an event
receiver, using the Microsoft C++ unified event model.
event_receiver is used with the event_source attribute and the __hook and __unhook keywords. Use
event_source to create event sources. Use __hook within an event receiver's methods to associate ("hook")
event receiver methods to the events of an event source. Use __unhook to disassociate them.
layout_dependent is only specified for COM event receivers ( type = com ). The default for layout_dependent is
false .
NOTE
A templated class or struct cannot contain events.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
Compiler attributes
event_source
__event
__hook
__unhook
Class attributes
event_source attribute
7/27/2022 • 2 minutes to read • Edit Online
NOTE
Event attributes in native C++ are incompatible with Standard C++. They don't compile when you specify /permissive-
conformance mode.
Syntax
[ event_source(type, optimize=[speed | size], decorate=[true | false]) ]
Parameters
type
An enumeration of one of the following values:
native for unmanaged C/C++ code (default for unmanaged classes).
com for COM code. Use coclass when type = com . This value requires that you include the following
header files:
#define _ATL_ATTRIBUTES
#include <atlbase.h>
#include <atlcom.h>
optimize
When type is native , you can specify optimize=size , to indicate that there are 4 bytes of storage (minimum)
for all events in a class or optimize=speed (the default) to indicate that there are 4 * (# of events) bytes of
storage.
decorate
When type is native , you can specify decorate=false , to indicate that the expanded name in the merged ( .mrg
) file shouldn't include the enclosing class name. /Fx lets you generate .mrg files. decorate=false , which is the
default, results in fully qualified type names in the merged file.
Remarks
The event_source C++ attribute specifies that the class or structure to which it's applied will be an event source.
event_source is used in conjunction with the event_receiver attribute and the __event keyword. Use
event_receiver to create event receivers. Use __event on methods within the event source to specify those
methods as events.
NOTE
A templated class or struct cannot contain events.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
Compiler attributes
event_receiver
__event
__hook
__unhook
Class attributes
export
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[export]
Remarks
The [export] C++ attribute causes a data structure to be placed in the .idl file and to then be available in the
type library in a binary-compatible format that makes it available for use with any language.
You cannot apply the [export] attribute to a class even if the class only has public members (the equivalent of a
struct ).
If you export an unnamed enum or struct , it is given a name that begins with __unnamed x, where x is a
sequential number.
The typedefs valid for export are base types, structs, unions, enums, or type identifiers. See typedef for more
information.
Example
The following code shows how to use the [export] attribute:
// cpp_attr_ref_export.cpp
// compile with: /LD
[module(name="MyLibrary")];
[export]
struct MyStruct {
int i;
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
Syntax
[ first_is("expression") ]
Parameters
expression
One or more C-language expressions. Empty argument slots are allowed.
Remarks
The first_is C++ attribute has the same functionality as the first_is MIDL attribute.
Example
The following code shows various ways to specify a section in an array:
// cpp_attr_ref_first_is.cpp
// compile with: /LD
#include "windows.h"
#include "unknwn.h"
[module(name="MyLib")];
[object, uuid(11111111-1111-1111-1111-111111111111)]
__interface b
{
[id(0), propget, bindable, displaybind, defaultbind,
requestedit] HRESULT get_I([out, retval]long *i);
HRESULT Proc1([in] short First, [in] short Last,
[first_is(First), last_is(Last), size_is(Last-First)] char Arr1[]);
HRESULT Proc2([in] short First, [in] short Last,
[last_is(First), size_is(Last)] char Arr2[]);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
Parameter Attributes
last_is
max_is
length_is
size_is
helpcontext
7/27/2022 • 2 minutes to read • Edit Online
Specifies a context ID that lets the user view information about this element in the Help file.
Syntax
[ helpcontext(id) ]
Parameters
id
The context ID of the help topic. See HTML Help: Context-Sensitive Help for Your Programs for more information
on context IDs.
Remarks
The helpcontext C++ attribute has the same functionality as the helpcontext MIDL attribute.
Example
See the example for defaultvalue for an example of how to use helpcontext .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Interface Attributes
Class Attributes
Method Attributes
Typedef, Enum, Union, and Struct Attributes
helpfile
helpstring
helpfile
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ helpfile("filename") ]
Parameters
filename
The name of the file that contains the help topics.
Remarks
The helpfile C++ attribute has the same functionality as the helpfile MIDL attribute.
Example
See the example for module for an example of how to use helpfile .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Interface Attributes
Class Attributes
Method Attributes
Typedef, Enum, Union, and Struct Attributes
helpcontext
helpstring
helpstring
7/27/2022 • 2 minutes to read • Edit Online
Specifies a character string that is used to describe the element to which it applies.
Syntax
[ helpstring("string") ]
Parameters
string
The text of the help string.
Remarks
The helpstring C++ attribute has the same functionality as the helpstring MIDL attribute.
Example
See the example for defaultvalue for an example of how to use helpstring .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Interface Attributes
Class Attributes
Method Attributes
Typedef, Enum, Union, and Struct Attributes
helpfile
helpcontext
helpstringcontext
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ helpstringcontext(contextID) ]
Parameters
contextID
A 32-bit Help context identifier in the Help file.
Remarks
The helpstringcontext C++ attribute has the same functionality as the helpstringcontext ODL attribute.
Example
// cpp_attr_ref_helpstringcontext.cpp
// compile with: /LD
#include <unknwn.h>
[module(name="MyLib")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Interface Attributes
Class Attributes
Method Attributes
module
helpstringdll
7/27/2022 • 2 minutes to read • Edit Online
Specifies the name of the DLL to use to perform document string lookup (localization).
Syntax
[ helpstringdll("string") ]
Parameters
string
The DLL to use to perform document string lookup.
Remarks
The helpstringdll C++ attribute has the same functionality as the helpstringdll MIDL attribute.
Example
// cpp_attr_ref_helpstringdll.cpp
// compile with: /LD
#include <unknwn.h>
[module(name="MyLib", helpstringdll="xx.dll")];
[object, uuid("00000000-0000-0000-0000-000000000001")]
__interface IMyI
{
HRESULT xxx();
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Interface Attributes
Class Attributes
Method Attributes
hidden
7/27/2022 • 2 minutes to read • Edit Online
Indicates that the item exists but should not be displayed in a user-oriented browser.
Syntax
[hidden]
Remarks
The hidden C++ attribute has the same functionality as the hidden MIDL attribute.
Example
See the example for bindable for an example of how to use hidden .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Interface Attributes
Class Attributes
Method Attributes
id
7/27/2022 • 2 minutes to read • Edit Online
Specifies a dispid parameter for a member function (either a property or a method, in an interface or
dispinterface).
Syntax
[ id(dispid) ]
Parameters
dispid
The dispatch ID for the interface method.
Remarks
The id C++ attribute has the same functionality as the id MIDL attribute.
Example
See the example for bindable for an example of how to use id .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Method Attributes
Data Member Attributes
defaultvalue
in
out
idl_module
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ idl_module (name=module_name, dllname=dll, uuid="uuid", helpstring="help text",
helpstringcontext=helpcontextID, helpcontext=helpcontext, hidden, restricted) ]
function_declaration
Parameters
name
A user-defined name for the code block that will appear in the .idl file.
dllname
(Optional) The .dll file that contains the export.
uuid
(Optional) A unique ID.
helpstring
(Optional) A character string used to describe the type library.
helpstringcontext
(Optional) The ID of a help topic in a .hlp or .chm file.
helpcontext
(Optional) The Help ID for this type library.
hidden
(Optional) A parameter that prevents the library from being displayed. For more information, see the hidden
MIDL attribute.
restricted
(Optional) Members of the library cannot be arbitrarily called. For more information, see the restricted MIDL
attribute.
function_declaration
The function that you'll define.
Remarks
The idl_module C++ attribute lets you specify the entry point in a .dll file, which allows you to import from a
.dll file.
The idl_module attribute has functionality similar to the module MIDL attribute.
You can export anything from a COM object that you can export from a .dll file by putting a DLL entry point
in the library block of an .idl file.
Use idl_module in two steps. First, define a name/DLL pair. Then, when you use idl_module to specify an entry
point, specify the name and any additional attributes.
Example
The following code shows how to use the idl_module attribute:
// cpp_attr_ref_idl_module.cpp
// compile with: /LD
[idl_quote("midl_pragma warning(disable:2461)")];
[module(name="MyLibrary"), idl_module(name="MyLib", dllname="xxx.dll")];
[idl_module(name="MyLib"), entry(4), usesgetlasterror]
void FuncName(int i);
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
See also
IDL attributes
Stand-alone attributes
entry
idl_quote
7/27/2022 • 2 minutes to read • Edit Online
Allows you to use IDL constructs that are not supported in the current version of Visual C++ and have them
pass through to the generated .idl file.
Syntax
[ idl_quote(text) ]
Parameters
text
The attribute name that you intend the Microsoft C++ compiler to pass through to the generated .idl file without
returning a compiler error.
Remarks
If the idl_quote C++ attribute is used as a stand-alone attribute (with a semicolon after the closing bracket),
then text is placed in the merged .idl file as is. If idl_quote is used on a symbol, text is placed within the attribute
block for that symbol.
Example
The following code shows how you could specify an unsupported attribute (using in , which is supported) and
how to define and use an undefined .idl construct:
// cpp_attr_ref_idl_quote.cpp
// compile with: /LD
#include <unknwn.h>
[module(name="MyLibrary")];
[export]
struct MYFLOT {
int i;
};
[export]
struct MYDUB {
int i;
};
union {
MYFLOT f1; MYDUB d2; } U1_TYPE;
} S1_TYPE;
[uuid("2F5F63F1-16DA-11d2-9E7B-00C04FB926DA"), object]
__interface IStatic{
HRESULT Func1([idl_quote("in")] int i);
HRESULT func( S1_TYPE* myStruct );
};
This code causes MYFLOT and MYDUB and the text entry to be placed in the generated .idl file. The name
parameter forces text to be placed before anything that references name in the generated .idl file. The
dependencies parameter forces the dependency list definitions to be placed before text in the generated .idl file.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
See also
IDL Attributes
Stand-Alone Attributes
iid_is
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ iid_is("expression") ]
Parameters
expression
A C language expression that specifies an IID of a COM interface pointed to by an interface pointer.
Remarks
The iid_is C++ attribute has the same functionality as the iid_is MIDL attribute.
Example
The following code shows the use of iid_is :
// cpp_attr_ref_iid_is.cpp
// compile with: /LD
#include "wtypes.h"
#include "unknwn.h"
[dispinterface, uuid("00000000-0000-0000-0000-000000000001")]
__interface IFireTabCtrl : IDispatch
{
[id(1)] HRESULT CreateInstance([in] REFIID riid,[out, iid_is("riid")]
IUnknown ** ppvObject);
};
[module(name="ATLFIRELib")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Parameter Attributes
immediatebind
7/27/2022 • 2 minutes to read • Edit Online
Indicates that the database will be notified immediately of all changes to a property of a data-bound object.
Syntax
[immediatebind]
Remarks
The immediatebind C++ attribute has the same functionality as the immediatebind MIDL attribute.
Example
See bindable for an example of how to use immediatebind .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Method Attributes
defaultbind
displaybind
requestedit
implements (C++)
7/27/2022 • 6 minutes to read • Edit Online
Specifies dispatch interfaces that are forced to be members of the IDL coclass.
Syntax
[ implements(
interfaces={interfaces}, dispinterfaces={dispinterfaces})]
Parameters
interfaces
A comma separated list of the interfaces that will be a member of the IDL coclass. A shorthand method for
specifying a single interface is implements( interface_name ) .
dispinterfaces
A comma separated list of the dispinterface that will be a member of the IDL coclass. A shorthand method for
specifying a single dispinterface is implements(dispinterfaces = dispinterface_name ) .
Remarks
By default, only COM-interfaces that are base classes of the coclass are added in the IDL coclass. implements
lets you force other interfaces to be IDL coclass members.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable Yes
Examples
The following example is in three parts: an .idl file and its associated .h file, and a C++ file.
Assume the following .idl file, which will be available to the compiler.
// attr_implements.idl
import "docobj.idl";
[ version(1.0), uuid(0ed71801-a1b6-3178-af3b-9431fc00185e) ]
library odod
{
importlib("stdole2.tlb");
importlib("olepro32.dll");
[
object, uuid(1AECC9BB-2104-3723-98B8-7CC54722C7DD)
]
interface IBar1 {
[id(1)] HRESULT bar1();
};
[
dual, uuid(1AECCABB-2104-3723-98B8-7CC54722C7DD)
]
interface IBar2 {
[id(1)] HRESULT bar2();
};
[
uuid(1AECC9CC-2104-3723-98B8-7CC54722C7DD)
]
dispinterface ISna {
properties:
methods:
[id(1)] HRESULT sna();
};
[
uuid(159A9BBB-E5F1-33F6-BEF5-6CFAD7A5933F), version(1.0)
]
coclass CBar {
interface IBar1;
interface IBar2;
dispinterface ISna;
};
}
And the following .h file, which also needs to be available to the compiler.
// attr_implements.h
// this ALWAYS GENERATED file contains definitions for the interfaces
/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#endif
#include "rpc.h"
#include "rpcndr.h"
#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif // __RPCNDR_H_VERSION__
#ifndef __attr_implements_h__
#define __attr_implements_h__
/* Forward Declarations */
#ifndef __IBar1_FWD_DEFINED__
#define __IBar1_FWD_DEFINED__
typedef interface IBar1 IBar1;
#endif /* __IBar1_FWD_DEFINED__ */
#ifndef __IBar2_FWD_DEFINED__
#define __IBar2_FWD_DEFINED__
typedef interface IBar2 IBar2;
#endif /* __IBar2_FWD_DEFINED__ */
#ifndef __ISna_FWD_DEFINED__
#define __ISna_FWD_DEFINED__
typedef interface ISna ISna;
#endif /* __ISna_FWD_DEFINED__ */
#ifndef __CBar_FWD_DEFINED__
#define __CBar_FWD_DEFINED__
#ifdef __cplusplus
typedef class CBar CBar;
#else
typedef struct CBar CBar;
#endif /* __cplusplus */
#endif /* __CBar_FWD_DEFINED__ */
#ifdef __cplusplus
extern "C"{
#endif
#ifndef __odod_LIBRARY_DEFINED__
#define __odod_LIBRARY_DEFINED__
/* library odod */
/* [uuid][version] */
#ifndef __IBar1_INTERFACE_DEFINED__
#define __IBar1_INTERFACE_DEFINED__
/* interface IBar1 */
/* [uuid][object] */
MIDL_INTERFACE("1AECC9BB-2104-3723-98B8-7CC54722C7DD")
IBar1
{
public:
BEGIN_INTERFACE
virtual /* [id] */ HRESULT STDMETHODCALLTYPE bar1( void) = 0;
END_INTERFACE
};
END_INTERFACE
} IBar1Vtbl;
interface IBar1
{
CONST_VTBL struct IBar1Vtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IBar1_bar1(This)\
(This)->lpVtbl -> bar1(This)
#endif /* COBJMACROS */
#endif /* __IBar1_INTERFACE_DEFINED__ */
#ifndef __IBar2_INTERFACE_DEFINED__
#define __IBar2_INTERFACE_DEFINED__
/* interface IBar2 */
/* [auto_handle][uuid][dual] */
MIDL_INTERFACE("1AECCABB-2104-3723-98B8-7CC54722C7DD")
IBar2
{
public:
BEGIN_INTERFACE
virtual /* [id] */ HRESULT STDMETHODCALLTYPE bar2( void) = 0;
END_INTERFACE
};
END_INTERFACE
} IBar2Vtbl;
interface IBar2
{
CONST_VTBL struct IBar2Vtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IBar2_bar2(This)\
(This)->lpVtbl -> bar2(This)
#endif /* COBJMACROS */
#endif /* __IBar2_INTERFACE_DEFINED__ */
#ifndef __ISna_DISPINTERFACE_DEFINED__
#define __ISna_DISPINTERFACE_DEFINED__
/* dispinterface ISna */
/* [uuid] */
MIDL_INTERFACE("1AECC9CC-2104-3723-98B8-7CC54722C7DD")
ISna : public IDispatch
{
};
interface ISna
{
CONST_VTBL struct ISnaVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define ISna_QueryInterface(This,riid,ppvObject)\
(This)->lpVtbl -> QueryInterface(This,riid,ppvObject)
#define ISna_AddRef(This)\
(This)->lpVtbl -> AddRef(This)
#define ISna_Release(This)\
(This)->lpVtbl -> Release(This)
#define ISna_GetTypeInfoCount(This,pctinfo)\
(This)->lpVtbl -> GetTypeInfoCount(This,pctinfo)
#define ISna_GetTypeInfo(This,iTInfo,lcid,ppTInfo)\
(This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo)
#define ISna_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId)\
(This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId)
#define ISna_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr)\
(This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr)
#endif /* COBJMACROS */
#endif /* __ISna_DISPINTERFACE_DEFINED__ */
#ifdef __cplusplus
class DECLSPEC_UUID("159A9BBB-E5F1-33F6-BEF5-6CFAD7A5933F")
CBar;
#endif
#endif /* __odod_LIBRARY_DEFINED__ */
#ifdef __cplusplus
}
#endif
#endif
In the following program, without implements, IBar1 , IBar2 , and ISna will not be in the coclass in the
generated IDL.
// attr_implements.cpp
// compile with: /LD /link /idlout:out.idl
#define _ATL_ATTRIBUTES 1
#include <atlbase.h>
#include <atlcom.h>
#include "attr_implements.h" // IDL generated header that contains a definition of the pseudo-interface
IBar and pseudo-dispinterface ISna
[module(name = "MyLib")];
[module(name = "MyLib")];
[dispinterface, uuid("00000000-0000-0000-0000-000000000001")]
__interface IMyInterface
{
[id(0)] long x;
[id(1)] HRESULT func();
};
[
coclass, uuid("00000000-0000-0000-0000-000000000002"), implements(interfaces={IBar1,IBar2},
dispinterfaces=ISna)
]
class CMyClass : public IMyInterface, public IBar1, public IDispatchImpl<IBar2, &__uuidof(IBar2)>, public
ISna
{
long _x;
public:
long get_x() { return _x; }
void put_x(long x0) { _x = x0; }
HRESULT func() { return S_OK; }
HRESULT __stdcall bar1() { return S_OK; }
HRESULT __stdcall bar2() { return S_OK; }
HRESULT __stdcall sna() { return S_OK; }
See also
Compiler Attributes
Class Attributes
implements_category
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ implements_category(implements_category="uuid") ]
Parameters
implements_category
The ID of the implemented category.
Remarks
The implements_categor y C++ attribute specifies the component categories implemented by the target class.
This is done by creating a CATEGORY map and adding separate entries specified by the implements_categor y
attribute. For more information, see Component Categories and How They Work.
This attribute requires that the coclass, progid, or vi_progid attribute (or another attribute that implies one of
these) also be applied to the same element. If any single attribute is used, the other two are automatically
applied. For example, if progid is applied, vi_progid and coclass are also applied.
Example
The following code specifies that the following object implements the Control category.
// cpp_attr_ref_implements_category.cpp
// compile with: /LD
#define _ATL_ATTRIBUTES
#include "atlbase.h"
#include "atlcom.h"
[module (name="MyLib")];
[ coclass, implements_category("CATID_Control"),
uuid("20a0d0cc-5172-40f5-99ae-5e032f3205ae")]
class CMyClass {};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable Yes
See also
COM Attributes
Class Attributes
IMPLEMENTED_CATEGORY
import
7/27/2022 • 2 minutes to read • Edit Online
Specifies another .idl, .odl, or header file containing definitions you want to reference from your main IDL.
Syntax
[ import(
idl_file
) ];
Parameters
idl_file
The name of an .idl file that you want imported into the type library of the current project.
Remarks
The impor t C++ attribute causes an #import statement to be placed below the import "docobj.idl" statement
in the generated .idl file. The impor t attribute has the same functionality as the import MIDL attribute.
The impor t attribute only places the specified file into the .idl file that will be generated by your project; the
impor t attribute does not let you call constructs in the specified file from source code in your project. To call
constructs in the specified file from source code in your project, either use #import and the embedded_idl
attribute or you can include the .h file for the idl_file, if a .h file exists.
Example
The following code:
// cpp_attr_ref_import.cpp
// compile with: /LD
[module(name="MyLib")];
[import(import.idl)];
import "docobj.idl";
import "import.idl";
[ uuid(EED3644C-8488-3ECD-BA97-147DB3CDB499), version(1.0) ]
library MyLib {
importlib("stdole2.tlb");
importlib("olepro32.dll");
...
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
See also
IDL Attributes
Stand-Alone Attributes
importidl
importlib
include
includelib
importidl
7/27/2022 • 2 minutes to read • Edit Online
Inserts the specified .idl file into the generated .idl file.
Syntax
[ importidl(idl_file) ];
Parameters
idl_file
Identifies the name of the .idl file that you want to merge with the .idl file that will be generated for your
application.
Remarks
The impor tidl C++ attribute places the section outside of the library block (in idl_file) into your program's
generated .idl file and the library section (in idl_file) into the library section of your program's generated .idl file.
You may want to use impor tidl , for example, if you want to use a hand-coded .idl file with your generated .idl
file.
Example
// cpp_attr_ref_importidl.cpp
// compile with: /LD
[module(name="MyLib")];
[importidl("import.idl")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
See also
Compiler Attributes
Stand-Alone Attributes
import
importlib
include
includelib
importlib
7/27/2022 • 2 minutes to read • Edit Online
Makes types that have already been compiled into another type library available to the type library being
created.
Syntax
[ importlib("tlb_file") ];
Parameters
tlb_file
The name of a .tlb file, in quotes, that you want imported into the type library of the current project.
Remarks
The impor tlib C++ attribute causes an importlib statement to be placed in the library block of the generated
.idl file. The impor tlib attribute has the same functionality as the importlib MIDL attribute.
Example
The following code shows an example of how to use impor tlib :
// cpp_attr_ref_importlib.cpp
// compile with: /LD
[module(name="MyLib")];
[importlib("importlib.tlb")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
See also
Compiler Attributes
Stand-Alone Attributes
import
importidl
include
includelib
in (C++)
7/27/2022 • 2 minutes to read • Edit Online
Indicates that a parameter is to be passed from the calling procedure to the called procedure.
Syntax
[in]
Remarks
The in C++ attribute has the same functionality as the in MIDL attribute.
Example
See bindable for an example of how to use in .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Parameter Attributes
Method Attributes
defaultvalue
id
out
include (C++)
7/27/2022 • 2 minutes to read • Edit Online
Specifies one or more header files to be included in the generated .idl file.
Syntax
[ include(header_file) ];
Parameters
header_file
The name of a file that you want included in the generated .idl file.
Remarks
The include C++ attribute causes an #include statement to be placed below the import "docobj.idl"
statement in the generated .idl file.
The include C++ attribute has the same functionality as the include MIDL attribute.
Example
The following code shows an example of how to use include . For this example, the file include.h contains only a
#include statement.
// cpp_attr_ref_include.cpp
// compile with: /LD
[module(name="MyLib")];
[include(cpp_attr_ref_include.h)];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
See also
IDL Attributes
Stand-Alone Attributes
import
importidl
includelib
importlib
includelib (C++)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ includelib(name.idl) ];
Parameters
name.idl
The name of the .idl file that you want included as part of the generated .idl file.
Remarks
The includelib C++ attribute causes an .idl or .h file to be included in the generated .idl file, after the importlib
statement.
Example
The following code is shown in a .cpp file:
// cpp_attr_ref_includelib.cpp
// compile with: /LD
[module(name="MyLib")];
[includelib("includelib.idl")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable Yes
See also
IDL Attributes
Stand-Alone Attributes
import
importidl
include
importlib
last_is
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ last_is("expression") ]
Parameters
expression
One or more C-language expressions. Empty argument slots are allowed.
Remarks
The last_is C++ attribute has the same functionality as the last_is MIDL attribute.
Example
See first_is for an example of how to specify a section of an array.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
Parameter Attributes
first_is
max_is
length_is
size_is
lcid
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[lcid]
Remarks
The lcid C++ attribute implements the functionality of the lcid MIDL attribute. If you want to implement locale
for a library block, use the lcid= lcid parameter to the module attribute.
Example
// cpp_attr_ref_lcid.cpp
// compile with: /LD
#include <unknwn.h>
[module(name="MyLibrary")];
typedef long HRESULT;
[dual, uuid("2F5F63F1-16DA-11d2-9E7B-00C04FB926DA")]
__interface IStatic {
HRESULT MyFunc([in, lcid] long LocaleID, [out, retval] BSTR * ReturnVal);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Parameter Attributes
length_is
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ length_is("expression") ]
Parameters
expression
One or more C-language expressions. Empty argument slots are allowed.
Remarks
The length_is C++ attribute has the same functionality as the length_is MIDL attribute.
Example
See first_is for an example of how to specify a section of an array.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
Parameter Attributes
first_is
max_is
last_is
size_is
library_block
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[library_block]
Remarks
When you place a construct inside the library block, you ensure that it will be passed into the type library,
regardless of whether it is referenced. By default, only constructs modified by the coclass, dispinterface, and
idl_module attributes are placed in the library block.
Example
In the following code, a custom interface is placed inside the library block.
// cpp_attr_ref_library_block.cpp
// compile with: /LD
#include <windows.h>
[module(name="MyLib")];
[object, library_block, uuid("9E66A290-4365-11D2-A997-00C04FA37DDB")]
__interface IMyInterface {
HRESULT f1();
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
See also
Compiler Attributes
Stand-Alone Attributes
licensed
7/27/2022 • 2 minutes to read • Edit Online
Indicates that the COM object to which it applies is licensed, and must be instantiated using IClassFactory2 .
Syntax
[licensed]
Remarks
The licensed C++ attribute has the same functionality as the licensed MIDL attribute.
Example
// cpp_attr_ref_licensed.cpp
// compile with: /LD
#include "unknwn.h"
[object, uuid("00000000-0000-0000-0000-000000000001")]
__interface IMyI : IUnknown {
HRESULT f();
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Class Attributes
local (C++)
7/27/2022 • 2 minutes to read • Edit Online
When used in the interface header, allows you to use the MIDL compiler as a header generator. When used in an
individual function, designates a local procedure for which no stubs are generated.
Syntax
[local]
Remarks
The local C++ attribute has the same functionality as the local MIDL attribute.
Example
See call_as for an example of how to use local .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
IDL Attributes
Interface Attributes
Method Attributes
call_as
max_is
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ max_is("expression") ]
Parameters
expression
One or more C-language expressions. Empty argument slots are allowed.
Remarks
The max_is C++ attribute has the same functionality as the max_is MIDL attribute.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
Example
See first_is for an example of how to specify a section of an array.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
Parameter Attributes
first_is
last_is
length_is
size_is
module (C++)
7/27/2022 • 4 minutes to read • Edit Online
Syntax
[ module (type=dll, name=string, version=1.0, uuid=uuid, lcid=integer, control=boolean, helpstring=string,
helpstringdll=string, helpfile=string, helpcontext=integer, helpstringcontext=integer, hidden=boolean,
restricted=boolean, custom=string, resource_name=string,) ];
Parameters
type
(Optional) Can be one of the following:
dll Adds functions and classes that allow the resulting DLL to function as a in-process COM server. This
is the default value.
exe Adds functions and classes that allow the resulting executable to function as a out of process COM
server.
service Adds functions and classes that allow the resulting executable to function as an NT service.
unspecified Disables injection of ATL code related to the module attribute: the injection of ATL Module
class, global instance _AtlModule and entry point functions. Does not disable injection of ATL code due to
other attributes in the project.
name
(Optional) The name of the library block.
version
(Optional) The version number you want to assign to the library block. The default value is 1.0.
uuid
The unique ID for the library. If you omit this parameter, an ID will be automatically generated for the library. You
may need to retrieve the uuid of your library block, which you can do by using the identifier __uuidof(
libraryname ) .
lcid
The localization parameter. See lcid for more information.
control
(Optional) Specifies that all coclasses in the library are controls.
helpstring
Specifies the type library.
helpstringdll
(Optional) Sets the name of the .dll file to use to perform a document string lookup. See helpstringdll for more
information.
helpfile
(Optional) The name of the Help file for the type library.
helpcontext
(Optional) The Help ID for this type library.
helpstringcontext
(Optional) See helpstringcontext for more information.
hidden
(Optional) Prevents the entire library from being displayed. This usage is intended for use with controls. Hosts
need to create a new type library that wraps the control with extended properties. See the hidden MIDL attribute
for more information.
restricted
(Optional) Members of the library cannot be called arbitrarily. See the restricted MIDL attribute for more
information.
custom
(Optional) One or more attributes; this is similar to the custom attribute. The first parameter to custom is the
GUID of the attribute. For example:
[module(custom={guid,1}, custom={guid1,2})]
resource_name
The string resource ID of the .rgs file used to register the APP ID of the DLL, executable, or service. When the
module is of type service, this argument is also used to obtain the ID of the string containing the service name.
NOTE
Both the .rgs file and the string containing the service name should contain the same numerical value.
Remarks
Unless you specify the restricted parameter to emitidl, module is required in any program that uses C++
attributes.
A library block will be created if, in addition to the module attribute, source code also uses dispinterface, dual,
object, or an attribute that implies coclass.
One library block is allowed in an .idl file. Multiple module entries in source code will be merged, with the most
recent parameter values being implemented.
If this attribute is used within a project that uses ATL, the behavior of the attribute changes. In addition to the
above behavior, the attribute also inserts a global object (called _AtlModule ) of the correct type and additional
support code. If the attribute is standalone, it inserts a class derived from the correct module type. If the
attribute is applied to a class, it adds a base class of the correct module type. The correct type is determined by
the value of the type parameter:
type = dll
CAtlDllModuleT is used as the base class and the standard DLL entry points required for a COM server.
These entry points are DllMain, DllRegisterServer, DllUnRegisterServer, DllCanUnloadNow, and
DllGetClassObject.
type = exe
CAtlExeModuleT is used as the base class and the standard executable entry point WinMain.
type = ser vice
CAtlServiceModuleT is used as the base class and the standard executable entry point WinMain.
type = unspecified
Disables injection of ATL code related to the module attribute.
Example
The following code shows how to create a library block in the generated .idl file.
// cpp_attr_ref_module1.cpp
// compile with: /LD
[module(name="MyLibrary", version="1.2", helpfile="MyHelpFile")];
The following code shows that you can provide your own implementation of a function that would appear in the
code that was injected as a result of using module . See /Fx for more information on viewing injected code. In
order to override one of the functions inserted by the module attribute, make a class that will contain your
implementation of the function and make the module attribute apply to that class.
// cpp_attr_ref_module2.cpp
// compile with: /LD /link /OPT:NOREF
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
#include <atlplus.h>
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
See also
IDL Attributes
Class Attributes
Stand-Alone Attributes
Typedef, Enum, Union, and Struct Attributes
usesgetlasterror
library
helpcontext
helpstring
helpfile
version
ms_union
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ms_union]
Remarks
The ms_union C++ attribute has the same functionality as the ms_union MIDL attribute.
Example
The following code shows the placement of ms_union :
// cpp_attr_ref_ms_union.cpp
// compile with: /LD
#include <unknwn.h>
[object, ms_union, uuid("00000000-0000-0000-0000-000000000001")]
__interface IFireTabCtrl {
HRESULT DisplayString([in, string] char * p1);
};
[module(name="ATLFIRELib")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
Syntax
[ no_injected_text(boolean) ];
Parameters
boolean
(Optional) true if you want no code injected, false to allow code to be injected. true is the default.
Remarks
The most common use of the no_injected_text C++ attribute is by the /Fx compiler option, which inserts the
no_injected_text attribute into the .mrg file.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
Compiler Attributes
nonbrowsable
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[nonbrowsable]
Remarks
The nonbrowsable C++ attribute has the same functionality as the nonbrowsable MIDL attribute.
Example
// cpp_attr_ref_nonbrowsable.cpp
// compile with: /LD
#include <unknwn.h>
[module(name="MyLib")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Method Attributes
noncreatable
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[noncreatable]
Remarks
The noncreatable C++ attribute has the same functionality as the noncreatable MIDL attribute and is
automatically passed through to the generated .IDL file by the compiler.
When this attribute is used within a project that uses ATL, the behavior of the attribute changes. In addition to
the above behavior, the attribute also injects the OBJECT_ENTRY_NON_CREATEABLE_EX_AUTO macro. This
macro indicates to ATL that the object cannot be created externally.
Example
// cpp_attr_ref_noncreatable.cpp
// compile with: /LD
#include <unknwn.h>
[module(name="MyLib")];
[object, uuid("11111111-1111-1111-1111-111111111111")]
__interface A
{
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Class Attributes
nonextensible
7/27/2022 • 2 minutes to read • Edit Online
Specifies that the IDispatch implementation includes only the properties and methods listed in the interface
description and cannot be extended with additional members at run time.
Syntax
[nonextensible]
Remarks
The nonextensible C++ attribute has the same functionality as the nonextensible MIDL attribute.
Use of nonextensible also requires the oleautomation attribute.
Example
The following code shows one use of the nonextensible attribute:
// cpp_attr_ref_nonextensible.cpp
// compile with: /LD
#include "unknwn.h"
[module(name="ATLFIRELib")];
[export] typedef long HRESULT;
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to interface
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Interface Attributes
object (C++)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[object]
Remarks
When preceding an interface definition, the object C++ attribute causes the interface to be placed in the .idl file
as a custom interface.
Any interface marked with object must inherit from IUnknown . This condition is satisfied if any of the base
interfaces inherit from IUnknown . If no base interfaces inherit from IUnknown , the compiler will cause the
interface marked with object to derive from IUnknown .
Example
See nonbrowsable for an example of how to use object .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to interface
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Interface Attributes
dual
dispinterface
custom
__interface
odl
7/27/2022 • 2 minutes to read • Edit Online
Identifies an interface as an Object Description Language (ODL) interface. The MIDL compiler does not require
the odl attribute; it is recognized only for compatibility with older .odl files.
Syntax
[odl]
Remarks
The odl C++ attribute has the same functionality as the odl MIDL attribute.
Example
// cpp_attr_ref_odl.cpp
// compile with: /LD
#include <unknwn.h>
[module(name="MyLIb")];
[coclass, uuid("00000000-0000-0000-0000-000000000002")]
class cmyClass : public IMyInterface
{
public:
HRESULT x(){}
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to interface
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Interface Attributes
oleautomation
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[oleautomation]
Remarks
The oleautomation C++ attribute has the same functionality as the oleautomation MIDL attribute.
Example
See the examples for defaultvalue and nonextensible for a sample use of oleautomation .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to interface
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Interface Attributes
optional (C++)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[optional]
Remarks
The optional C++ attribute has the same functionality as the optional MIDL attribute.
Example
The following code shows how optional might be used:
// cpp_attr_ref_optional.cpp
// compile with: /LD
#include "unknwn.h"
[module(name="ATLFIRELib")];
[dispinterface, uuid("00000000-0000-0000-0000-000000000001")]
__interface IFireTabCtrl : IDispatch
{
[id(1)] long procedure ([in, optional] VARIANT i);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Parameter Attributes
out (C++)
7/27/2022 • 2 minutes to read • Edit Online
Identifies pointer parameters that are returned from the called procedure to the calling procedure (from the
server to the client).
Syntax
[out]
Remarks
The out C++ attribute has the same functionality as the out MIDL attribute.
Example
See the example for bindable for a sample use of out .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Parameter Attributes
defaultvalue
id
pointer_default
7/27/2022 • 2 minutes to read • Edit Online
Specifies the default pointer attribute for all pointers, except top-level pointers that appear in parameter lists.
Syntax
[ pointer_default(value) ]
Parameters
value
A value that describes the pointer type: ptr , ref , or unique .
Remarks
The pointer_default C++ attribute has the same functionality as the pointer_default MIDL attribute.
Example
See the example for defaultvalue for a sample use of pointer_default .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to interface
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Interface Attributes
pragma
7/27/2022 • 2 minutes to read • Edit Online
Emits the specified string into the generated .idl file without the use of quotation marks.
Syntax
[ pragma(pragma_statement) ];
Parameters
pragma_statement
The pragma that you want to go into the generated .idl file.
Remarks
The pragma C++ attribute has the same functionality as the pragma MIDL attribute.
Example
// cpp_attr_ref_pragma.cpp
// compile with: /LD
#include "unknwn.h"
[module(name="MyLib")];
[pragma(pack(4))];
[dispinterface, uuid("00000000-0000-0000-0000-000000000001")]
__interface A
{
[id(1)] HRESULT MyMethod ([in, satype("BSTR")] SAFEARRAY **p);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Anywhere
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Stand-Alone Attributes
pack
progid
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ progid(name) ];
Parameters
name
The ProgID representing the object.
ProgIDs present a human-readable version of the class identifier (CLSID) used to identify COM/ActiveX objects.
Remarks
The progid C++ attribute lets you specify the ProgID for a COM object. A ProgID has the form
name1.name2.version. If you do not specify a version for a ProgID, the default version is 1. If you do not specify
name1.name2, the default name is classname.classname. If you do not specify progid and you do specify
vi_progid , name1.name2 are taken from vi_progid and the (next sequential number) version is appended.
If an attribute block that uses progid does not also use uuid , the compiler will check the registry to see if a
uuid exists for the specified progid . If progid is not specified, the version (and coclass name, if creating a
coclass) will be used to generate a progid .
progid implies the coclass attribute, that is, if you specify progid , it is the same thing as specifying the
coclass and progid attributes.
The progid attribute causes a class to be automatically registered under the specified name. The generated .idl
file will not display the progid value.
When this attribute is used within a project that uses ATL, the behavior of the attribute changes. In addition to
the above behavior, the information specified with this attribute is used in the GetProgID function, injected by
the coclass attribute. For more information, see the coclass attribute.
Example
See the example for coclass for a sample use of progid .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Class Attributes
Typedef, Enum, Union, and Struct Attributes
ProgID Key
propget
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[propget]
Remarks
The propget C++ attribute has the same functionality as the propget MIDL attribute.
Example
See the example for bindable for a sample use of propget .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Method
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Method Attributes
propput
propputref
propput
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[propput]
Remarks
The propput C++ attribute has the same functionality as the propput MIDL attribute.
Example
See the example for bindable for a sample use of propput .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Method
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Method Attributes
propget
propputref
propputref
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[propputref]
Remarks
The propputref C++ attribute has the same functionality as the propputref MIDL attribute.
Example
See the example for bindable for a sample use of propputref .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to Method
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Method Attributes
propget
propput
ptr
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ptr]
Remarks
The ptr C++ attribute has the same functionality as the ptr MIDL attribute.
Example
See the example for defaultvalue for a sample use of ptr .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Interface Attributes
Method Attributes
Typedef, Enum, Union, and Struct Attributes
public (C++ Attributes)
7/27/2022 • 2 minutes to read • Edit Online
Ensures that a typedef will go into the type library even if it is not referenced from within the .idl file.
Syntax
[public]
Remarks
The public C++ attribute has the same functionality as the public MIDL attribute.
Example
The following code shows how to use the public attribute:
// cpp_attr_ref_public.cpp
// compile with: /LD
#include "unknwn.h"
[module(name="ATLFIRELib")];
[export, public] typedef long MEMBERID;
[dispinterface, uuid(99999999-9999-9999-9999-000000000000)]
__interface IFireTabCtrl : IDispatch
{
[id(2)] long procedure ([in, optional] VARIANT i);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to typedef
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
range (C++)
7/27/2022 • 2 minutes to read • Edit Online
Specifies a range of allowable values for arguments or fields whose values are set at run time.
Syntax
[ range(low, high) ]
Parameters
low
The low range value.
high
The high range value.
Remarks
The range C++ attribute has the same functionality as the range MIDL attribute.
Example
// cpp_attr_ref_range.cpp
// compile with: /LD
#include <unknwn.h>
[module(name="MyLib")];
[object, uuid("9E66A290-4365-11D2-A997-00C04FA37DDB")]
__interface ICustom {
HRESULT Custom([in] long l, [out, retval] long *pLong);
HRESULT length_is1([in, range(0, 999)] long f, [in, length_is(f)] char array[10]);
HRESULT length_is2([in, range(-99, -1)] long f, [in, length_is("f"), size_is(10)] char *array);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Method Attributes
Parameter Attributes
Data Member Attributes
rdx
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ rdx(key, valuename=NULL, regtype) ]
Parameters
key
The name of the key to be created or opened.
valuename
(Optional) Specifies the value field to be set. If a value field with this name does not already exist in the key, it is
added.
regtype
The type of registry key being added. Can be one of the following: text , dword , binary , or CString .
Remarks
The rdx C++ attribute creates or modifies an existing registry key for a COM component. The attribute adds a
BEGIN_RDX_MAP macro to the object that implements the target member. RegistryDataExchange , a function
injected as a result of the BEGIN_RDX_MAP macro, can be used to transfer data between the registry and the
data members
This attribute can be used in conjunction with the coclass, progid, or vi_progid attributes or other attributes that
implies one of these.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
Example
The following code adds a registry key called MyValue to the system describing the CMyClass COM component.
// cpp_attr_ref_rdx.cpp
// compile with: /LD /link /OPT:NOREF
#define _ATL_ATTRIBUTES
#include "atlbase.h"
[module (name="MyLib")];
class CMyClass {
public:
CMyClass() {
strcpy_s(m_sz, "SomeValue");
}
See also
COM Attributes
registration_script
readonly (C++)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[readonly]
Remarks
The readonly C++ attribute has the same functionality as the readonly MIDL attribute.
If you want to prohibit modification of a method parameter, then use the in attribute.
Example
The following code shows a use of the readonly attribute:
// cpp_attr_ref_readonly.cpp
// compile with: /LD
[idl_quote("midl_pragma warning(disable:2461)")];
#include "unknwn.h"
[module(name="ATLFIRELib")];
[dispinterface, uuid(11111111-1111-1111-1111-111111111111)]
__interface IFireTabCtrl
{
[readonly, id(1)] int i();
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Data Member Attributes
ref (C++)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ref]
Remarks
The ref C++ attribute has the same functionality as the ref MIDL attribute.
Example
The following code shows how to use the ref attribute:
// cpp_attr_ref_ref.cpp
// compile with: /LD
#include <windows.h>
[module(name="ATLFIRELib")];
[dispinterface, uuid("00000000-0000-0000-0000-000000000001")]
__interface IFireTabCtrl
{
[id(1), unique] char * GetFirstName([in, ref] char * pszFullName );
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
Parameter Attributes
registration_script
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ registration_script(script) ]
Parameters
script
The full path to a custom registration script (.rgs) file. A value of none , such as script = "none" , indicates that
the coclass has no registration requirements.
Remarks
The registration_script C++ attribute executes the custom registration script specified by script. If this
attribute is not specified, a standard .rgs file (containing information for registering the component) is used. For
more information on .rgs files, see The ATL Registry Component (Registrar).
This attribute requires that the coclass, progid, or vi_progid attribute (or another attribute that implies one of
these) also be applied to the same element.
Example
The following code specifies that the component has a registry script called cpp_attr_ref_registration_script.rgs.
// cpp_attr_ref_registration_script.cpp
// compile with: /LD
#define _ATL_ATTRIBUTES
#include "atlbase.h"
#include "atlcom.h"
[module (name="REG")];
[object, uuid("d9cd196b-6836-470b-9b9b-5b04b828e5b0")]
__interface IFace {};
// requires "cpp_attr_ref_registration_script.rgs"
// create sample .RGS file "cpp_attr_ref_registration_script.rgs" if it does not exist
[ coclass, registration_script(script="cpp_attr_ref_registration_script.rgs"),
uuid("50d3ad42-3601-4f26-8cfe-0f1f26f98f67")]
class CMyClass:public IFace {};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
COM Attributes
Class Attributes
rdx
requestedit
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[requestedit]
Remarks
The requestedit C++ attribute has the same functionality as the requestedit MIDL attribute.
Example
See the example for bindable for a sample use of requestedit .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Method Attributes
Data Member Attributes
defaultbind
displaybind
immediatebind
requires_category
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ requires_category(
requires_category) ]
Parameters
requires_category
The ID of the required category.
Remarks
The requires_categor y C++ attribute specifies the component categories required by the target class. For
more information, see REQUIRED_CATEGORY.
This attribute requires that the coclass, progid, or vi_progid attribute (or another attribute that implies one of
these) also be applied to the same element.
Example
The following code requires that the object implement the Control category.
// cpp_attr_ref_requires_category.cpp
// compile with: /LD
#define _ATL_ATTRIBUTES
#include "atlbase.h"
#include "atlcom.h"
[module (name="MyLibrary")];
[ coclass, requires_category("CATID_Control"),
uuid("1e1a2436-f3ea-4ff3-80bf-5409370e8144")]
class CMyClass {};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
COM Attributes
implements_category
restricted
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ restricted(
interfaces
) ]
Parameters
interfaces
One or more interfaces that may not be called arbitrarily on a COM object. This parameter is only valid when
applied to a class.
Remarks
The restricted C++ attribute has the same functionality as the restricted MIDL attribute.
Example
The following code shows how to use the restricted attribute:
// cpp_attr_ref_restricted.cpp
// compile with: /LD
#include "windows.h"
#include "unknwn.h"
[module(name="MyLib")];
[object, uuid("00000000-0000-0000-0000-000000000001")]
__interface a
{
};
[object, uuid("00000000-0000-0000-0000-000000000002")]
__interface b
{
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Interface Attributes
Method Attributes
retval
7/27/2022 • 2 minutes to read • Edit Online
Designates the parameter that receives the return value of the member.
Syntax
[retval]
Remarks
The retval C++ attribute has the same functionality as the retval MIDL attribute.
retval must appear on the last argument in a function's declaration.
Example
See the example for bindable for a sample use of retval .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
Invalid attributes in
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Parameter Attributes
Method Attributes
satype
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ satype(data_type) ]
Parameters
data_type
The data type for the SAFEARRAY data structure that is being passed as a parameter to an interface method.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
Remarks
The satype C++ attribute specifies the data type of the SAFEARRAY .
NOTE
A level of indirection is dropped from the SAFEARRAY pointer in the generated .idl file from how it is declared in the .cpp
file.
Example
// cpp_attr_ref_satype.cpp
// compile with: /LD
#include "unknwn.h"
[module(name="MyModule")];
[dispinterface, uuid("00000000-0000-0000-0000-000000000001")]
__interface A {
[id(1)] HRESULT MyMethod ([in, satype("BSTR")] SAFEARRAY **p);
};
See also
Compiler Attributes
Parameter Attributes
Method Attributes
id
size_is
7/27/2022 • 2 minutes to read • Edit Online
Specify the size of memory allocated for sized pointers, sized pointers to sized pointers, and single- or
multidimensional arrays.
Syntax
[ size_is("expression") ]
Parameters
expression
The size of memory allocated for sized pointers.
Remarks
The size_is C++ attribute has the same functionality as the size_is MIDL attribute.
Example
See the example for first_is for a sample of how to specify a section of an array.
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
Parameter Attributes
first_is
last_is
max_is
length_is
source (C++)
7/27/2022 • 2 minutes to read • Edit Online
On a class, specifies the COM object's source interfaces for connection points. On a property or method,
indicates that the member returns an object or VARIANT that is a source of events.
Syntax
[ source(interfaces) ]
Parameters
interfaces
One or more interfaces that you specify when you apply the source attribute to a class. This parameter is not
used when source is applied to a property or method.
Remarks
The source C++ attribute has the same functionality as the source MIDL attribute.
You can use the default attribute to specify the default source interface for an object.
Example
// cpp_attr_ref_source.cpp
// compile with: /LD
#include "windows.h"
#include "unknwn.h"
[module(name="MyLib")];
[object, uuid(11111111-1111-1111-1111-111111111111)]
__interface b
{
[id(0), propget, bindable, displaybind, defaultbind, requestedit]
HRESULT get_I([out, retval]long *i);
};
[object, uuid(11111111-1111-1111-1111-111111111131)]
__interface c
{
[id(0), propget, bindable, displaybind, defaultbind, requestedit]
HRESULT et_I([out, retval]long *i);
};
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Class Attributes
Method Attributes
coclass
string (C++)
7/27/2022 • 2 minutes to read • Edit Online
Indicates that the one-dimensional char , wchar_t , byte (or equivalent) array or the pointer to such an array
must be treated as a string.
Syntax
[string]
Remarks
The string C++ attribute has the same functionality as the string MIDL attribute.
Example
The following code shows how to use string on an interface and on a typedef:
// cpp_attr_ref_string.cpp
// compile with: /LD
#include "unknwn.h"
[module(name="ATLFIRELib")];
[export, string] typedef char a[21];
[dispinterface, restricted, uuid("00000000-0000-0000-0000-000000000001")]
__interface IFireTabCtrl
{
[id(1)] HRESULT Method3([in, string] char *pC);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Array Attributes
export
support_error_info
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ support_error_info(error_interface=uuid) ]
Parameters
error_interface
The identifier of the interface implementing IErrorInfo .
Remarks
The suppor t_error_info C++ attribute implements support for returning detailed, contextual errors
encountered by the target object to the client. For the object to support errors, the methods of the IErrorInfo
interface must be implemented by the object. For more information, see Supporting IDispatch and IErrorInfo.
This attribute adds the ISupportErrorInfoImpl class as a base class to the target object. This results in a default
implementation of ISupportErrorInfo and can be used when a single interface generates errors on an object.
Example
The following code adds default support for the ISupportErrorInfo interface to the CMyClass object.
// cpp_attr_ref_support_error_info.cpp
// compile with: /LD
#define _ATL_ATTRIBUTES
#include "atlbase.h"
#include "atlcom.h"
[module (name="mymod")];
[object, uuid("f0b17d66-dc6e-4662-baaf-76758e09c878")]
__interface IMyErrors
{
};
[ coclass, support_error_info("IMyErrors"),
uuid("854dd392-bdc7-4781-8667-8757936f2a4f") ]
class CMyClass
{
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to class
AT T RIB UT E C O N T EXT VA L UE
Repeatable Yes
For more information about the attribute contexts, see Attribute Contexts.
See also
COM Attributes
Class Attributes
switch_is
7/27/2022 • 2 minutes to read • Edit Online
Specifies the expression or identifier acting as the union discriminant that selects the union member.
Syntax
[switch_is]
Remarks
The switch_is C++ attribute has the same functionality as the switch_is MIDL attribute.
Example
See the case example for a sample use of switch_is .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to typedef
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
switch_type
switch_type
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[switch_type(
type
}]
Parameters
type
The switch type, can be an integer, character, Boolean, or enumeration type.
Remarks
The switch_type C++ attribute has the same functionality as the switch_type MIDL attribute.
C++ attributes do not support encapsulated unions. Nonencapsulated unions are supported only in the
following form:
// cpp_attr_ref_switch_type.cpp
// compile with: /LD
#include <windows.h>
[module(name="MyLibrary")];
[ export ]
struct SizedValue2 {
[switch_type("char"), switch_is(kind)] union {
[case(1), string]
wchar_t* wval;
[default, string]
char* val;
};
char kind;
};
Example
See the case example for a sample use of switch_type .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to typedef
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
export
synchronize
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[synchronize]
Remarks
The synchronize C++ attribute implements support for synchronizing the target method of an object.
Synchronization allows multiple objects to use a common resource (such as a method of a class) by controlling
the access of the target method.
The code inserted by this attribute calls the proper Lock method (determined by the threading model) at the
beginning of the target method. When the method is exited, Unlock is automatically called. For more
information on these functions, see CComAutoThreadModule::Lock
This attribute requires that the coclass, progid, or vi_progid attribute (or another attribute that implies one of
these) also be applied to the same element. If any single attribute is used, the other two are automatically
applied. For example, if progid is applied, vi_progid and coclass are also applied.
Example
The following code provides synchronization for the UpdateBalance method of the CMyClass object.
// cpp_attr_ref_synchronize.cpp
// compile with: /LD
#define _ATL_ATTRIBUTES
#include "atlbase.h"
#include "atlcom.h"
[module(name="SYNC")];
[coclass,
threading(both),
vi_progid("MyProject.MyClass"),
progid("MyProject.MyClass.1"),
uuid("7a7baa0d-59b8-4576-b754-79d07e1d1cc3")
]
class CMyClass {
float m_nBalance;
[synchronize]
void UpdateBalance(float nAdjust) {
m_nBalance += nAdjust;
}
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
COM Attributes
threading (C++)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ threading(model=enumeration) ]
Parameters
model
(Optional) One of the following threading models:
apartment (apartment threading)
neutral (.NET Framework components with no user interface)
single (simple threading)
free (free threading)
both (apartment and free threading)
The default value is apartment .
Remarks
The threading C++ attribute does not appear in the generated .idl file but will be used in the implementation of
your COM object.
In ATL projects, If the coclass attribute is also present, the threading model specified by model is passed as the
template parameter to the CComObjectRootEx class, inserted by the coclass attribute.
The threading attribute also guards access to an event_source.
Example
See the licensed example for a sample use of threading .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
See also
COM Attributes
Typedef, Enum, Union, and Struct Attributes
Class Attributes
Multithreading Support for Older Code (Visual C++)
Neutral Apartments
transmit_as
7/27/2022 • 2 minutes to read • Edit Online
Instructs the compiler to associate a presented type that client and server applications manipulate, with a
transmitted type.
Syntax
[ transmit_as(type) ]
Parameters
type
Specifies the data type that is transmitted between client and server.
Remarks
The transmit_as C++ attribute has the same functionality as the transmit_as MIDL attribute.
Example
The following code shows a use of the transmit_as attribute:
// cpp_attr_ref_transmit_as.cpp
// compile with: /LD
#include "windows.h"
[module(name="MyLibrary")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to typedef
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
export
uidefault
7/27/2022 • 2 minutes to read • Edit Online
Indicates that the type information member is the default member for display in the user interface.
Syntax
[uidefault]
Remarks
The uidefault C++ attribute has the same functionality as the uidefault MIDL attribute.
Example
The following code shows a sample of uidefault :
// cpp_attr_ref_uidefault.cpp
// compile with: /LD
#include "unknwn.h"
[module(name="MyLib")];
[object, uuid("9E66A290-4365-11D2-A997-00C04FA37DDB")]
__interface ICustom{
HRESULT Custom([in] long l, [out, retval] long *pLong);
[uidefault]HRESULT id0([in] long l);
[uidefault]HRESULT id1([in] long l);
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Method Attributes
unique (C++)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[unique]
Remarks
The unique C++ attribute has the same functionality as the unique MIDL attribute.
Example
See the ref example for a sample use of unique .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
Parameter Attributes
usesgetlasterror
7/27/2022 • 2 minutes to read • Edit Online
Tells the caller that if there is an error when calling that function, then the caller can then call GetLastError to
retrieve the error code.
Syntax
[usesgetlasterror]
Remarks
The usesgetlasterror C++ attribute has the same functionality as the usesgetlasterror MIDL attribute.
Example
See the idl_module example for a sample of how to use usesgetlasterror .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
uuid (C++ Attributes)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ uuid( "uuid" ) ]
Parameters
uuid
A 128-bit, unique identifier.
Remarks
If the definition of an interface or class does not specify the uuid C++ attribute, then the Microsoft C++
compiler will provide one. When you specify a uuid , you must include the quotes.
If you do not specify uuid , then the compiler will generate the same GUID for interfaces or classes with the
same name in different attribute projects on a machine.
You can use Uuidgen.exe or Guidgen.exe to generate your own unique IDs. (To run either of these tools, click
Star t and click Run on the menu. Then enter the name of the required tool.)
When used in a project that does not also use ATL, specifying the uuid attribute is the same as specifying the
uuid __declspec modifier. To retrieve the uuid of a class, you can use __uuidof
Example
See the bindable example for a sample use of uuid .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Interface Attributes
Class Attributes
Typedef, Enum, Union, and Struct Attributes
uuid
v1_enum
7/27/2022 • 2 minutes to read • Edit Online
Directs that the specified enumerated type be transmitted as a 32-bit entity rather than the 16-bit default.
Syntax
[v1_enum]
Remarks
The v1_enum C++ attribute has the same functionality as the v1_enum MIDL attribute.
Example
The following code shows a use of v1_enum :
// cpp_attr_ref_v1_enum.cpp
// compile with: /LD
[module(name="MyLibrary")];
[export, v1_enum]
enum eList {
e1 = 1, e2 = 2
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
vararg
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[vararg]
Remarks
The vararg C++ attribute has the same functionality as the vararg MIDL attribute.
Example
The following code shows a use of vararg :
// cpp_attr_ref_vararg.cpp
// compile with: /LD
#include "unknwn.h"
#include "oaidl.h"
[module(name="MyLibrary")];
[object, uuid("00000000-0000-0000-0000-000000000001")]
__interface X : public IUnknown
{
[vararg] HRESULT Button([in, satype(VARIANT)]SAFEARRAY *psa);
};
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Method Attributes
version (C++)
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ version("version") ]
Parameters
version
The version number of the coclass . If not specified, 1.0 will be placed in the .idl file.
Remarks
The version C++ attribute has the same functionality as the version MIDL attribute and is passed through to
the generated .idl file.
Example
See the bindable example for a sample use of version .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
Compiler Attributes
Class Attributes
vi_progid
7/27/2022 • 2 minutes to read • Edit Online
Syntax
[ vi_progid(name) ];
Parameters
name
The version-independent ProgID representing the object.
ProgIDs present a human-readable version of the class identifier (CLSID) used to identify COM/ActiveX objects.
Remarks
The vi_progid C++ attribute lets you specify a version-independent ProgID for a COM object. A ProgID has the
form name1.name2.version. A version-independent ProgID does not have a version. It is possible to specify both
the progid and the vi_progid attributes on a coclass . If you do not specify vi_progid , the version-
independent ProgID is the value specified by the progid attribute.
vi_progid implies the coclass attribute, that is, if you specify vi_progid , it is the same thing as specifying the
coclass and vi_progid attributes.
The vi_progid attribute causes a class to be automatically registered under the specified name. The generated
.idl file will not display the ProgID value.
In ATL projects, If the coclass attribute is also present, the specified ProgID is used by the
GetVersionIndependentProgID function (inserted by the coclass attribute).
Example
See the coclass example for a sample use of vi_progid .
Requirements
AT T RIB UT E C O N T EXT VA L UE
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes
Class Attributes
ProgID Key
wire_marshal
7/27/2022 • 2 minutes to read • Edit Online
Specifies a data type that will be used for transmission instead of an application-specific data type.
Syntax
[wire_marshal]
Remarks
The wire_marshal C++ attribute has the same functionality as the wire_marshal MIDL attribute.
Example
The following code shows a use of wire_marshal :
// cpp_attr_ref_wire_marshal.cpp
// compile with: /LD
#include "windows.h"
[module(name="MyLibrary")];
Requirements
AT T RIB UT E C O N T EXT VA L UE
Applies to typedef
Repeatable No
For more information about the attribute contexts, see Attribute Contexts.
See also
IDL Attributes
Typedef, Enum, Union, and Struct Attributes