解决VS2005编译 typedef void * POINTER_64 PVOID64错误

   今天用VS2005编译DXSDK示例代码,出现如下错误,

c:/program files/microsoft visual studio 8/vc/platformsdk/include/winnt.h(222) : error C2146: 语法错误 : 缺少“;”(在标识符“PVOID64”的前面)
c:/program files/microsoft visual studio 8/vc/platformsdk/include/winnt.h(222) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
c:/program files/microsoft visual studio 8/vc/platformsdk/include/winnt.h(5940) : error C2146: 语法错误 : 缺少“;”(在标识符“Buffer”的前面)
c:/program files/microsoft visual studio 8/vc/platformsdk/include/winnt.h(5940) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
c:/program files/microsoft visual studio 8/vc/platformsdk/include/winnt.h(5940) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

在网上搜了下,有几种解决方法,总结如下:

 

Solution 1.
工具->选项->项目和解决方案->vc++目录
试试调换一下include的次序

不过估计一样
建议下载platformSDK,并安装,而不是使用2005自带psdk
个人意见,可能有错

Solution 2.
typedef void *PVOID;
typedef void * POINTER_64 PVOID64;
在它之前加下:
#define POINTER_64 __ptr64

Solution 3.
typedef void *PVOID;
typedef void * POINTER_64;
typedef void * PVOID64;

 

后两种测试有效,第一种应该也可以。


### C语言中 `typedef void* sw_tim_handle_t` 的作用和用法 在C语言中,`typedef` 是一种用于创建类型别名的关键字。通过 `typedef`,可以为已有的数据类型定义一个新的名称,从而提高代码的可读性和可维护性。以下是关于 `typedef void* sw_tim_handle_t` 的具体作用和用法: #### 1. **作用** - 定义了一个新的类型别名 `sw_tim_handle_t`,它实际上是一个指向 `void` 类型的指针[^4]。 - `void*` 表示该指针可以指向任何数据类型,因为它不与特定的数据类型绑定。这种通用性使得 `void*` 指针非常适合用作函数参数或返回值,尤其是在需要传递不同类型数据的情况下。 #### 2. **用法** - **作为函数参数**:可以使用 `sw_tim_handle_t` 作为函数参数,以接收任意类型的指针。 - **作为函数返回值**:如果一个函数需要返回一个不确定类型的指针,可以将其返回值类型定义为 `sw_tim_handle_t`。 - **封装复杂类型**:通过将复杂的指针类型(如 `void*`)封装为简单的类型别名,可以使代码更加清晰易懂。 以下是一个具体的代码示例,展示如何使用 `typedef void* sw_tim_handle_t`: ```c // 定义类型别名 typedef void* sw_tim_handle_t; // 使用 sw_tim_handle_t 作为函数参数 void initialize_timer(sw_tim_handle_t handle) { // 假设 handle 是一个指向定时器结构体的指针 if (handle == NULL) { printf("Handle is invalid!\n"); } else { printf("Timer initialized successfully.\n"); } } // 使用 sw_tim_handle_t 作为函数返回值 sw_tim_handle_t create_timer() { void* timer = malloc(sizeof(struct Timer)); // 假设 Timer 是一个结构体 return timer; // 返回一个 void* 类型的指针 } int main() { sw_tim_handle_t my_timer = create_timer(); // 创建定时器 initialize_timer(my_timer); // 初始化定时器 free(my_timer); // 释放内存 return 0; } ``` #### 3. **注意事项** - **类型转换**:由于 `void*` 指针没有绑定到特定的数据类型,在使用时需要显式地将其转换为目标类型。例如: ```c struct Timer { int period; }; sw_tim_handle_t handle = create_timer(); struct Timer* timer = (struct Timer*)handle; // 显式类型转换 ``` - **避免误用**:虽然 `void*` 指针非常灵活,但过度使用可能导致代码难以维护。因此,建议仅在确实需要通用指针的情况下使用 `sw_tim_handle_t`。 --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值