我正在编写一个程序来控制flashbulb。闪光灯响应用户的按键而闪光。我试图限制闪光灯的出现规律,以防止灯泡烧毁。我已经从这个论坛得到了一些帮助,但是我无法用我自己的方式实现这些代码。使用A类用户建议,具体如下:实现具有时间限制代码的类很难(C++)
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);
}
}
};
我收到了几个语法错误,我似乎无法转移,所有这些都是在任一类的第一个或最后一个括号 - “语法错误:标识符'bulb'“,”语法错误:';'“,”语法错误:'}'“和”语法错误:'}'“。尽管如此,我从来没有和班级一起工作过,所以期待这与此有关。我哪里错了?
请注意'10000'是闪光之间的最小延迟。
''我收到一些语法错误'' - 请将您收到的所有错误都复制到您的问题中。您提供的数据越多,您获得的相关答案就越多。 – pts 2011-05-14 13:18:26
您需要在类声明的'}'后面的代码末尾使用分号。 – pts 2011-05-14 13:20:23
谢谢,我已经添加到上述,以及我收到的错误 – CaptainProg 2011-05-14 13:26:35