gpt4 book ai didi

c - 使用 CreateEvent 调用编译 C 代码时出错

转载 作者:太空宇宙 更新时间:2023-11-04 06:41:34 25 4
gpt4 key购买 nike

如果我在 Visual Studio 2005 中编译以下函数,我会遇到几个编译错误:

void search()
{
deviceEventHandle = CreateEvent(NULL, FALSE, FALSE, "foundDevice");

BTUINT32 deviceClass = 0; // 0 represents all classes
BTUINT16 maxDevices = 200; // 0 represents an unlimited number of responses
BTUINT16 maxDuration = 45; // maxDuration * 1.28 = number of seconds
Btsdk_StartDeviceDiscovery(deviceClass, maxDevices, maxDuration);

WaitForSingleObject(deviceEventHandle, INFINITE);

if (deviceEventHandle != NULL) {
CloseHandle(deviceEventHandle);
deviceEventHandle = NULL;
}
}

这些是我得到的错误:

error C2275: 'BTUINT32' : illegal use of this type as an expression 
error C2146: syntax error : missing ';' before identifier 'deviceClass'
error C2065: 'deviceClass' : undeclared identifier
error C2275: 'BTUINT16' : illegal use of this type as an expression
error C2146: syntax error : missing ';' before identifier 'maxDevices'
error C2065: 'maxDevices' : undeclared identifier
error C2275: 'BTUINT16' : illegal use of this type as an expression
error C2146: syntax error : missing ';' before identifier 'maxDuration'
error C2065: 'maxDuration' : undeclared identifier

如果我注释掉包含 CreateEvent 调用的行,代码将编译无误:

void search()
{
//deviceEventHandle = CreateEvent(NULL, FALSE, FALSE, "foundDevice");

BTUINT32 deviceClass = 0; // 0 represents all classes
BTUINT16 maxDevices = 200; // 0 represents an unlimited number of responses
BTUINT16 maxDuration = 45; // maxDuration * 1.28 = number of seconds
Btsdk_StartDeviceDiscovery(deviceClass, maxDevices, maxDuration);

WaitForSingleObject(deviceEventHandle, INFINITE);

if (deviceEventHandle != NULL) {
CloseHandle(deviceEventHandle);
deviceEventHandle = NULL;
}


}

这些是我使用的 header :

#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include "Btsdk_ui.h"

我在 Visual Studio 2005 中将代码编译为 C 代码 (/TC)。“Btsdk_ui.h”文件是 BlueSoleil 蓝牙堆栈的一部分,并包含另一个包含 BTUINT32 和 BTUINT16 定义的文件。

欢迎所有建议。

最佳答案

在 C 中,您在 block 的开头声明所有变量。

deviceEventHandle = CreateEvent(NULL, FALSE, FALSE, "foundDevice"); 移到 BTUINT 变量 block 之后。

关于c - 使用 CreateEvent 调用编译 C 代码时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7413323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com