1

I am trying to make my webcam Win32 application save more than one photo at a time i.e. save one photo then another then another etc.

To do this, I am appending a string to an integer variable so that each new photo name can be unique and conform to the format of the second argument of CreateBMPFile. This would usually be a case of writing TEXT("string literal"), but I need to keep modifying the filename as each new photo is created.

PBITMAPINFO pbi = CreateBitmapInfoStruct(hwnd, hbm);
int i = 1;
std::string image = "..\\..\\..\\..\\WebCam\\frame" + std::to_string(i) + ".bmp";
while (!exists(image)) {
    LPTSTR filename = (LPTSTR)image.c_str();
    CreateBMPFile(hwnd, filename, pbi, hbm, hdcMem);
    i++;
}

This compiles and executes, however, when I click the "Grab Frame" button and it attempts to save it, the application crashes i.e. I cannot see the GUI anymore and it becomes a stagnant process.

I am using an exists() function to see whether the file exists in the system:

inline bool exists(const std::string& name) {
    struct stat buffer;
    return (stat(name.c_str(), &buffer) == 0);
}

I've also tried using sprintf_s() with the same result of crashing the application.

user3295336
  • 51
  • 10
  • 1
    You need to be more specific about what "crashes the program" means, as that is a very vague problem description. What **specific** problem are you having? (If you don't understand the need for specificity, try calling your doctor and saying "I have a pain. What's causing it and how do I make it stop?" and see if you get an answer without providing more information. – Ken White Jul 05 '14 at 23:58
  • @KenWhite I click the "Grab Frame" button and when it attempts to save it, the application crashes i.e. I cannot see the GUI anymore and it becomes a stagnant process. I am unsure of what has really happened. – user3295336 Jul 06 '14 at 00:00
  • Please [edit] your question and add that information there, where it can be seen, instead of burying it in a comment. The next step would be to use the debugger, and see where the problem is happening. Examining variables at that point should give you an indication of what's going on. – Ken White Jul 06 '14 at 00:04
  • 1
    Note that you never rebuild your `image` string - simply incrementing `i` doesn't magically cause the string to update with the new number in it. – Jonathan Potter Jul 06 '14 at 00:29

0 Answers0