【发布时间】:2011-05-14 13:10:27
【问题描述】:
我正在编写一个程序来控制闪光灯。闪光灯响应用户的按键而触发。我试图限制闪光灯的发生规律,以防止灯泡烧坏。我已经从这个论坛获得了一些帮助,但是我无法用我自己的代码来实现。一位用户建议使用一个类,如下:
class bulb
{
__int64 clocks;
__int64 frequency;
public:
bulb()
{
LARGE_INTEGER li;
QueryPerformanceFrequency(&li);
frequency = li.QuadPart;
clocks = 0;
}
void WINAPI flash (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
// If this is the first occurence, set the 'clocks' to system time (+10000 to allow flash to occur)
if (clocks == 0) clocks = li.QuadPart + 10000;
__int64 timepassed = clocks - li.QuadPart;
if (timepassed >= (((double)frequency) / 10000))
{
//Set the clock
clocks = li.QuadPart;
//Define the serial port procedure
HANDLE hSerial;
//Open the serial port (fire the flash)
hSerial = CreateFile("COM1", GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
//Close the serial port
CloseHandle(hSerial);
}
}
};
我收到一些似乎无法转换的语法错误,所有这些错误都位于类的第一个或最后一个括号 - “语法错误:标识符'灯泡'”,“语法错误:';' ”、“语法错误:'}'”和“语法错误:'}'”。不过,我以前从未使用过课程,所以希望这与此有关。我哪里错了?
请注意“10000”是闪烁之间的最小延迟。
【问题讨论】:
-
``我收到一些语法错误'' -- 请将您收到的所有错误复制到您的问题中。您提供的数据越多,您获得的相关答案就越多。
-
你需要在代码的最后一个分号,在类声明的
}之后。 -
谢谢,我已将其添加到上面,以及收到的错误
-
我看到你还没有声明
hSerial -
谢谢 - 也解决了这个问题。同样的错误适用:S