How to check comment or uncomment from an INI file

Jun 8, 2012 at 12:38pm
Hi all
In one of my program i have a defined a condition like //#define _WRITE_MPEG_ (1)

If this is un-commented program will write something to a file otherwise it will stream data

#if !defined (_WRITE_MPEG_ )
InitBufferHandling();
StartRTPProcess();


#endif

Now i want to control this from an INI file,i want to check from whether #define _WRITE_MPEG_ (1) is commented or uncommented or not and take action accordingly...

How to do this?
Jun 8, 2012 at 1:16pm
Well, let me tell you that, if you want user-control, you should compile your program with both probabilities, so, DO NOT use #define, use IF/ELSE.
Like, make a bool global, and while initializing your program check if you find the requested line in your ini file. If you find it, set your global to true.
Then, at that point into your code, have a simple if, like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <...> // After all your inclusion files
bool g_WriteMPEGBool = 0;
// ...
int main() // Entrypoint
{
     FILE * Settings = fopen("settings.ini","r");
     // Look for the requested option to be set here
     if(OptionIsSet)
          g_WriteMPEGBool = 1;
// ...
if(g_WriteMPEGBool)
{
     InitBufferHandling();
     StartRTPProcess();
}
Jun 8, 2012 at 4:09pm
EssGeEich absolutely right, but use GetPrivateProfileInt/GetPrivateProfileString to read a .ini file.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724345%28v=vs.85%29.aspx
Jun 8, 2012 at 4:52pm
Oh. I used to get informations from INI files by myself, and never knew about that.
Jun 8, 2012 at 5:34pm
It's an old WIN16 thing that's in the long forgotten past, but still supported :)
Jun 8, 2012 at 5:38pm
There are cross-platform implementations of INI files, most of them have additional features.
Topic archived. No new replies allowed.