3

im trying to use this code:

bool SaveBMPFile(char *filename, HBITMAP bitmap, HDC bitmapDC, int width, int height);

bool ScreenCapture(int x, int y, int width, int height, char *filename){
// get a DC compat. w/ the screen
HDC hDc = CreateCompatibleDC(0);

// make a bmp in memory to store the capture in
HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height);

// join em up
SelectObject(hDc, hBmp);

// copy from the screen to my bitmap
BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY);

// save my bitmap
bool ret = SaveBMPFile(filename, hBmp, hDc, width, height);

// free the bitmap memory
DeleteObject(hBmp);

return ret;
}

it throws these errors:

bot.c|185|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'SaveBMPFile'|
bot.c|187|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ScreenCapture'|

What can I do? tried different code won't work, and tried use Gdi+- also errors.

Rodrigo Guedes
  • 1,169
  • 2
  • 13
  • 27
Orr Goren
  • 75
  • 1
  • 4

2 Answers2

6

I think you are missing #include <stdbool.h>.

bool is not a primitive type in C. You must include the <stdbool.h> header to obtain its definition.

Dan Moulding
  • 211,373
  • 23
  • 97
  • 98
  • Oh damn you are right! haha thank you! but there is another error: undefined reference to `SaveBMPFile`. – Orr Goren Oct 16 '12 at 19:55
  • @OrrGoren By the way, since you're new here, I thought I would point out that if someone has answered your question (like Dan has), it is polite to click the checkmark to the left of the answer, which indicates that the question is answered and gives Dan a little bit of reputation. – Brian Campbell Oct 16 '12 at 20:17
  • @OrrGoren: SaveBMPFile is not a Windows SDK function. Go back to where ever you acquired this code and look for the additional function. And if Dan answered your question (which it appears that he did), please remember to click the checkmark so he gets the credit. – David Wohlferd Dec 12 '14 at 00:27
2

It's likely your error is actually before the code that you showed. The error message says that it's expecting one of those things; so it's likely there's a line you didn't terminate with a semicolon (;) or a function you didn't terminate with a close brace (}) before the excerpt that you have shown. One thing is to make sure that you didn't paste this into the middle of another function; you can't nest functions in C.

Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
  • Checked the code twice-there is no errors, want me to paste the entire code? – Orr Goren Oct 16 '12 at 19:54
  • @OrrGoren I think that Dan's answer got it. – Brian Campbell Oct 16 '12 at 19:59
  • Yeah but there is another error: Undefined reference to `SaveBMPFile` - what could it be? – Orr Goren Oct 16 '12 at 20:00
  • @OrrGoren You either need to define that function, or link to a library that defines it. Where did you get that code snippet from? It should provide instructions on how to link it, or a definition for that function. If you can't figure that out yourself, I'd recommend asking another question about `SaveBMPFile`. The error in this question has been answered, trying to ask more in comments doesn't work well on StackOverflow. Make sure you tag it with `winapi`, so that people know you're talking about Windows. – Brian Campbell Oct 16 '12 at 20:03
  • @OrrGoren It looks like the code you are using was copied from [this forum thread](http://www.daniweb.com/software-development/cpp/threads/119804/screenshot-maybe-win32api#post593378). Notice that it says "The SaveBMPFile function referenced above is attached (I didn't write it)" and provides an attachment that contains the definition. – Brian Campbell Oct 16 '12 at 20:07