Member Avatar for rajshrimohanks

I came across this program in the C++ section. How to do something similar in C? Let me elaborate.
I want to read the colour values of individual pixels in at the rate of at least about 25Hz. I have a nVidia GeForce GTS450 graphic card and Windows 7 64-bit/Linux Mint 13 64-bit dual booting. I want to write a C program which would perform the said task and pass the values continuously to an Arduino through the USB. I can handle the Arduino part. But how do I get the values in the first place?
I know Windows 7 64-bit won't allow me to read the values directly from the graphic card. Is there any way I can do it using a C program and some other library?
How do I do the same in Linux Mint 64-bit?

Recommended Answers

All 2 Replies

I came across this program in the C++ section. How to do something similar in C?

While that program is indeed written in C++, the conversion to C is trivial as the overall structure doesn't depend on anything specific to C++. The library being used is Windows' Win32 API.

I see only a few minor things that need to be changed (there may be multiple instances of each):

  1. Variable declarations mixed with statements may not be legal in your version of C. Declare all variables at the start of a block.

  2. The bool type may not be available in your version of C (if it is, include <stdbool.h>). You can replace it with int, and true/false with 1 and 0.

  3. Replace <iostream> with <stdio.h>.

  4. Remove using namespace std;

  5. Either remove cin.ignore(); or replace it with getchar();.

Member Avatar for rajshrimohanks

While that program is indeed written in C++, the conversion to C is trivial as the overall structure doesn't depend on anything specific to C++. The library being used is Windows' Win32 API.

Thanks for the timely reply. I can work on it. I have a few more queries though:

  1. My main intention is actually to read the pixel RGB values to send them to an Arduino. In this case, I wouldn't need to save the BMP file. Just read the values and send them directly to the microcontroller via an USB port. So is there any function in windows.h to achieve this? Or if it isn't, how can I modify the ScreenCapture function to suit my task?

  2. I am new to Windows programming using C, though I am proficient in normal C programming. Can you suggest some resources to learn windows programming from?

  3. How do I make a similar program to run in Linux Mint 13 64-bit? windows.h won't work in it right?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.