VCCodeModel.AddMacro Method (String, Object, String, Object)


Adds a #define element to a specific file.

Namespace:   Microsoft.VisualStudio.VCCodeModel
Assembly:  Microsoft.VisualStudio.VCCodeModel (in Microsoft.VisualStudio.VCCodeModel.dll)

VCCodeMacro AddMacro(
	string Name,
	object Location,
	string Value = "",
	object Position


Type: System.String

Required. Specifies the name of the macro.

Type: System.Object

Required. The path or file name of the file to be modified. If the file does not exist, it is created automatically. The file is added to the project if it is not already a project item. If the file cannot be created and added to the project, then AddMacro fails.

Type: System.String

Optional. The text of the macro's definition.

Type: System.Object

Optional. Default = 0. The code element after which to add the new element. If the value is a CodeElement, then the new element is added immediately after it.

Since collections begin their count at one, passing 0 indicates that the new element should be placed at the beginning of the collection. A value of -1 means the element should be placed at the end.

Call this function to add a #define Directive (C/C++) element to the specified file.

See How to: Compile Example Code for Visual C++ Code Model Extensibility for information on how to compile and run this sample.

This example adds a macro statement to the stdafx.h file.

Sub AddMacro()
    Dim codeModel As VCCodeModel
    codeModel = DTE.Solution.Item(1).CodeModel
    Dim macro As VCCodeMacro
    macro = codeModel.AddMacro("LAST_CHAR", "File.h", "'Z'")
End Sub
Return to top