Header annotations describe how a function uses its parameters and return value. These annotations have been added to many of the Windows header files to help you ensure that you are calling the Windows API correctly. If you enable code analysis, the Visual Studio 2005 compiler will produce level 6000 warnings if you are not calling these functions per the usage described through the annotations. You can also add these annotations in your own code to ensure that it is being called correctly. To enable code analysis in Visual Studio, go to the Project menu, click Properties, click Code Analysis, and enable the feature. For more information, see the documentation for Visual Studio 2005.
These annotations are defined in Specstrings.h. They are built on primitives that are part of the Standard Annotation Language (SAL) and implemented using _declspec("SAL_*").
There are two classes of annotations: buffer annotations and advanced annotations.
Buffer Annotations
Buffer annotations describe how functions use their pointers and can be used to detect buffer overruns. Each parameter may use zero or one buffer annotation. A buffer annotation is constructed with a leading underscore and the components described in the following sections.
Buffer size Description
(size)
Specifies the total size of the buffer. Use with _bcount and _ecount; do not use with _part. This value is the accessible space; it may be less than the allocated space.
(size,length)
Specifies the total size and initialized length of the buffer. Use with _bcount_part and _ecount_part. The total size may be less than the allocated space.
Buffer size units Description
_bcount
The buffer size is in bytes.
_ecount
The buffer size is in elements.
Direction Description
_in
The function reads from the buffer. The caller provides the buffer and initializes it.
_inout
The function both reads from and writes to buffer. The caller provides the buffer and initializes it. If used with _deref, the buffer may be reallocated by the function.
_out
The function writes to the buffer. If used on the return value or with _deref, the function provides the buffer and initializes it. Otherwise, the caller provides the buffer and the function initializes it.
Indirection Description
_deref
Dereference the parameter to obtain the buffer pointer. This parameter may not be NULL.
_deref_opt
Dereference the parameter to obtain the buffer pointer. This parameter can be NULL.
Initialization Description
_full
The function initializes the entire buffer. Use only with output buffers.
_part
The function initializes part of the buffer, and explicitly indicates how much. Use only with output buffers.
Required or optional buffer Description
_opt
This parameter can be NULL.
The following example shows the annotations for the GetModuleFileName function. The hModule parameter is an optional input parameter . The lpFilename parameter is an output parameter; its size in characters is specified by the nSize parameter and its length includes the null-terminating character. The nSize parameter is an input parameter.
Copy Code
DWORD
WINAPI
GetModuleFileName(
__in_opt HMODULE hModule,
__out_ecount_part(nSize, return + 1) LPTSTR lpFilename,
__in DWORD nSize
);
The following are the annotations defined in Specstrings.h. Use the information in the tables above to interpret their meaning.
__bcount(size)
__bcount_opt(size)
__deref_bcount(size)
__deref_bcount_opt(size)
__deref_ecount(size)
__deref_ecount_opt(size)
__deref_in
__deref_in_bcount(size)
__deref_in_bcount_opt(size)
__deref_in_ecount(size)
__deref_in_ecount_opt(size)
__deref_in_opt
__deref_inout
__deref_inout_bcount(size)
__deref_inout_bcount_full(size)
__deref_inout_bcount_full_opt(size)
__deref_inout_bcount_opt(size)
__deref_inout_bcount_part(size,length)
__deref_inout_bcount_part_opt(size,length)
__deref_inout_ecount(size)
__deref_inout_ecount_full(size)
__deref_inout_ecount_full_opt(size)
__deref_inout_ecount_opt(size)
__deref_inout_ecount_part(size,length)
__deref_inout_ecount_part_opt(size,length)
__deref_inout_opt
__deref_opt_bcount(size)
__deref_opt_bcount_opt(size)
__deref_opt_ecount(size)
__deref_opt_ecount_opt(size)
__deref_opt_in
__deref_opt_in_bcount(size)
__deref_opt_in_bcount_opt(size)
__deref_opt_in_ecount(size)
__deref_opt_in_ecount_opt(size)
__deref_opt_in_opt
__deref_opt_inout
__deref_opt_inout_bcount(size)
__deref_opt_inout_bcount_full(size)
__deref_opt_inout_bcount_full_opt(size)
__deref_opt_inout_bcount_opt(size)
__deref_opt_inout_bcount_part(size,length)
__deref_opt_inout_bcount_part_opt(size,length)
__deref_opt_inout_ecount(size)
__deref_opt_inout_ecount_full(size)
__deref_opt_inout_ecount_full_opt(size)
__deref_opt_inout_ecount_opt(size)
__deref_opt_inout_ecount_part(size,length)
__deref_opt_inout_ecount_part_opt(size,length)
__deref_opt_inout_opt
__deref_opt_out
__deref_opt_out_bcount(size)
__deref_opt_out_bcount_full(size)
__deref_opt_out_bcount_full_opt(size)
__deref_opt_out_bcount_opt(size)
__deref_opt_out_bcount_part(size,length)
__deref_opt_out_bcount_part_opt(size,length)
__deref_opt_out_ecount(size)
__deref_opt_out_ecount_full(size)
__deref_opt_out_ecount_full_opt(size)
__deref_opt_out_ecount_opt(size)
__deref_opt_out_ecount_part(size,length)
__deref_opt_out_ecount_part_opt(size,length)
__deref_opt_out_opt
__deref_out
__deref_out_bcount(size)
__deref_out_bcount_full(size)
__deref_out_bcount_full_opt(size)
__deref_out_bcount_opt(size)
__deref_out_bcount_part(size,length)
__deref_out_bcount_part_opt(size,length)
__deref_out_ecount(size)
__deref_out_ecount_full(size)
__deref_out_ecount_full_opt(size)
__deref_out_ecount_opt(size)
__deref_out_ecount_part(size,length)
__deref_out_ecount_part_opt(size,length)
__deref_out_opt
__ecount(size)
__ecount_opt(size)
__in
__in_bcount(size)
__in_bcount_opt(size)
__in_ecount(size)
__in_ecount_opt(size)
__in_opt
__inout
__inout_bcount(size)
__inout_bcount_full(size)
__inout_bcount_full_opt(size)
__inout_bcount_opt(size)
__inout_bcount_part(size,length)
__inout_bcount_part_opt(size,length)
__inout_ecount(size)
__inout_ecount_full(size)
__inout_ecount_full_opt(size)
__inout_ecount_opt(size)
__inout_ecount_part(size,length)
__inout_ecount_part_opt(size,length)
__inout_opt
__out
__out_bcount(size)
__out_bcount_full(size)
__out_bcount_full_opt(size)
__out_bcount_opt(size)
__out_bcount_part(size,length)
__out_bcount_part_opt(size,length)
__out_ecount(size)
__out_ecount_full(size)
__out_ecount_full_opt(size)
__out_ecount_opt(size)
__out_ecount_part(size,length)
__out_ecount_part_opt(size,length)
__out_opt
Advanced Annotations
Advanced annotations provide additional information about the parameter or return value. Each parameter or return value may use zero or one advanced annotation.
Annotation Description
__blocksOn(resource)
The functions blocks on the specified resource.
__callback
The function can be used as a function pointer.
__checkReturn
Callers must check the return value.
__format_string
The parameter is a string that contains printf-style % markers.
__in_awcount(expr,size)
If the expression is true at exit, the size of the input buffer is specified in bytes. If the expression is false, the size is specified in elements.
__nullnullterminated
The buffer may be accessed up to and including the first sequence of two null characters or pointers.
__nullterminated
The buffer may be accessed up to and including the first null character or pointer.
__out_awcount(expr,size)
If the expression is true at exit, the size of the output buffer is specified in bytes. If the expression is false, the size is specified in elements.
__override
Specifies C#-style override behavior for virtual methods.
__reserved
The parameter is reserved for future use and must be zero or NULL.
__success(expr)
If the expression is true at exit, the caller can rely on all guarantees specified by other annotations. If the expression is false, the caller cannot rely on the guarantees. This annotation is automatically added to functions that return an HRESULT value.
__typefix(ctype)
Treat the parameter as the specified type rather than its declared type.
The following examples show the buffer and advanced annotations for the DeleteTimerQueueTimer, FreeEnvironmentStrings, and UnhandledExceptionFilter functions.
Copy Code
__checkReturn
BOOL
WINAPI
DeleteTimerQueueTimer(
__in_opt HANDLE TimerQueue,
__in HANDLE Timer,
__in_opt HANDLE CompletionEvent
);
BOOL
WINAPI
FreeEnvironmentStrings(
__in __nullnullterminated LPTCH
);
__callback
LONG
WINAPI
UnhandledExceptionFilter(
__in struct _EXCEPTION_POINTERS *ExceptionInfo
);
See Also
SAL Annotations
Walkthrough: Analyzing C/C++ Code for Defects
分享到:
相关推荐
import springfox.documentation.swagger2.annotations.EnableSwagger2; @WebAppConfiguration @EnableSwagger2 @EnableWebMvc public class SwaggerConfig { @Bean public Docket customDocket() { ...
3) Using JAX-RS annotations to specify how the parameters can be passed from a client to the web resource, via http request header, from the URL path, from request body, from cookies, etc. 4) Using ...
**CMSIS Configuration Wizard** 是一个强大的工具,专为开发者设计,旨在简化ARM Cortex-M系列处理器上使用CMSIS( Cortex Microcontroller Software Interface Standard)时的配置过程。这个工具的最大亮点在于,...
HeaderInfo Represents a header element, such as <? InitiatorInfo The init directive in the ZUML page. LanguageDefinition A definition of a language, such as xul. NativeInfo Represents the ...
koroFileHeader在vscode中用于生成文件头部注释和函数注释的插件,经过多版迭代后,插件:支持所有主流语言,灵活方便,文档齐全,食用简单觉得插件不错的话,就给个 :star:吧〜使用效果:头部注释和注释图案函数...
在这个例子中,`record`对象包含了读取的所有信息,你可以通过`.seq`获取序列,通过`.id`获取标识符,通过`.letter_annotations["phred_quality"]`获取质量分数。 除了`Biopython`,你还可以使用`pysam`库,虽然它...
在设计Header部分时,我们可以使用矩形工具创建一个矩形,并将其设置为Header的底部颜色。然后,我们可以添加Logo图像,并将其设置为合适的宽度和高度。 在设计登录框时,我们可以使用文本输入框和按钮工具创建登录...
- `jackson-annotations-2.10.0.jar`: Jackson的注解库,用于支持注解驱动的JSON序列化和反序列化。 - `jjwt-0.7.0.jar`: Java JWT库,用于创建、验证和解码JWT,是实现JWT认证的关键库。 - `jjwt-jackson-0.11.1...
- **Header Type for XPath Header Enricher**:新增了对XPath头增强器的支持,可以通过XPath查询来动态设置消息头。 - **ObjectToJson Transformer: Node Result**:增加了将对象转换为JSON的功能。 - **JMS ...
import org.apache.http.Header; import org.apache.http.HttpException; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; ...
XFire使用注解(Annotations)和XML配置文件,让开发者能够快速地创建和部署SOAP服务。以下是一个简单的XFire服务和客户端代码示例: ```java // XFire服务端 @Service("userService") @SOAPBinding(style = Style....
- 若需额外的文字介绍,可以在Annotations栏添加,这将在原型完成后供UI设计参考。 通过以上步骤,你可以创建一个初步的SNS社区首页原型。在Axure RP Pro中,还可以添加交互动作,如链接跳转、按钮点击效果等,使...
1. 同样进入 `Settings` -> `File and Code Templates` -> `Includes`,然后选择 `File Header`。 2. 在这里,你可以定义文件头部的通用信息,比如作者、版权信息等。这些信息会在每个新文件中自动添加。 ### 二、...
Filter 的配置可以通过 annotations 或 XML 文件进行配置。在 Spring Boot 中,可以使用 @WebFilter 注解来配置 Filter。 例如: ```java @Component @ServletComponentScan @WebFilter(urlPatterns = "/login/*", ...
SOAP消息通常包含三个部分:Header(头部,用于传递元数据和控制信息)、Body(主体,包含实际的请求或响应信息)和Envelope(封装整个消息)。 4. **JAX-WS (Java API for XML Web Services)**: JAX-WS是Java平台...
在Android应用开发中,网络请求是必不可少的一部分。为了提高开发效率和代码的可维护性,开发者通常...在实际项目中,还可以进一步扩展,例如增加网络状态监听、统一错误处理、自定义Header等功能,以满足复杂的需求。
SOAP消息通常包含三个主要部分:Header(头)用于传递元数据,Body(主体)包含实际的消息内容,而Envelope(封装)则是整个消息的容器。 **WSDL(Web Services Description Language)** WSDL是一种XML格式,用于...
- **地图框架和轴标注**(Map frame and axes annotations: The –B option):提供了自定义地图框架和轴标注的方法。 - **头部数据记录**(Header data records: The –H option):解释了如何处理包含头部信息的...
TypeScript定义了接口(Interfaces)和类型注解(Type Annotations),帮助开发者更好地理解和维护代码结构。 在now-jwt-master压缩包中,可能包含了以下文件和目录: 1. `src/`:源代码目录,包含了主要的实现文件...