Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5844413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:17:19+00:00 2026-05-22T12:17:19+00:00

I am writing a program to control a flashbulb. The flash fires in response

  • 0

I am writing a program to control a flashbulb. The flash fires in response to a key press by the user. I am trying to limit the occurence regularity of the flash to prevent the bulb burning out. I have already received some help from this forum, but am unable to implement the code with my own. A user suggested using a class, as follows:

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);
        }
    }
};

I receive a few syntax errors that I can’t seem to shift, all of which are at either the first or last bracket of the class – “syntax error : identifier ‘bulb'”, “syntax error : ‘;'”, “syntax error : ‘}'” and “syntax error : ‘}'”. I have never worked with classes before though, so expect this is something to do with that. Where am I going wrong?

Please note ‘10000’ is the minimum delay between flashes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:17:20+00:00Added an answer on May 22, 2026 at 12:17 pm

    There are a few major issues with your code:

    • Missing a ‘;’ at the end of the class definition.
    • Missing a definition HANDLE hSerial before it is used.
    • You are comparing the time and frequency incorrectly on the line if (timepassed >= (((double)frequency) / 10000)). If you wish to convert the counter from QueryPerformanceCounter into a real time use something like:

      double RealTime = (double) clocks / (double) frequency;

    If you are getting other error messages they are related to the code before or after the snippet you posted. A few more minor issues and comments:

    • Both QueryPerformanceFrequency and QueryPerformanceCounter can fail. Unless getting invalid values doesn’t matter you should be checking the return values from these.
    • You open a COM port but don’t write anything to it or confirm that the open succeeded or not.
    • To avoid future issues the if statement if (clocks == 0) should all be on one line or include brackets, i.e., one of:

    :

    if (clocks == 0) clocks = li.QuadPart + 10000;
    
    if (clocks == 0) {
        clocks = li.QuadPart + 10000;
    }
    

    Edit: Example for converting QueryPerformanceCounter into real times (error checking not included):

    LARGE_INTEGER Frequency;
    LARGE_INTEGER Counter;
    
    QueryPerformanceFrequency(&Frequency);
    QueryPerformanceCounter(&Counter);
    
       //Time in seconds
    double RealTime = (double) Counter.QuadPart / (double)Frequency.QuadPart;
    
    LARGE_INTEGER Counter1;
    QueryPerformanceCounter(&Counter1);
    
       //Elapsed time in seconds
    double DeltaTime = (double) (Counter1.QuadPart - Counter.QuadPart) / (double)Frequency.QuadPart;
    

    See Also: How to use QueryPerformanceCounter?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program in VS 2005 and I wanna control the access
I'm writing a software for a call-center. It's somewhat like a ATM program: user
I'm writing a program that sends an email out at a client's specific local
I am writing a program which has two panes (via CSplitter ), however I
If you are writing a program that is executable from the command line, you
I'm writing a program (for Mac OS X, using Objective-C) and I need to
I'm writing a program to read from a POP3 mailbox and upload the email
I'm writing a program that uses SetWindowRgn to make transparent holes in a window
I am writing a program in Python that will act as a server and
I'm writing a program that contains a generational garbage collector. There are just two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.