| View previous topic :: View next topic |
| Author |
Message |
Pro-surf Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Dec 2007 Posts: 1415 Location: Under Ur Bed , Moauahauha
|
Posted: Sat Aug 01, 2009 11:02 am Post subject: [Question] C++ Write / Read from a INI file |
|
|
so i noticed how many trainers can write and read from an INI file
like read values or read if the checkbox is ticked or not..
and i really need it so, how ???
Im really slow in C++ so make it understand able
thanks
_________________
ProsTrain VIP |..........| - 80% Done im close to the finish line
 |
|
| Back to top |
|
 |
DoomsDay Grandmaster Cheater
Reputation: 0
Joined: 06 Jan 2007 Posts: 768 Location: %HomePath%
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Aug 02, 2009 4:04 am Post subject: |
|
|
ps. microsoft 'recommends' you use registry as .ini files are 'obsolete' now but it's sort of personal choice. some people don't like changes to registry since it makes settings and stuff less easy to port to another machine. and a lot of apps fail to clean up registry properly after uninstalling.
there is one very cool method i read about the other day. which is to save your settings in the executable file itself. then edit the .exe with the new settings every time the user changes them. very cool imo, i'll make an example for that when i'm done with my current project
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun Aug 02, 2009 4:12 am Post subject: |
|
|
Embedding the settings in your own exe does not sound very useful...
I tried to write my own .ini routines a while ago, but it ended up being more of a pain in that ass than I expected. Can't say I recommend doing it unless you like wasting a lot of time.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Aug 02, 2009 4:19 am Post subject: |
|
|
yes i also wrote my own .ini routines a while ago accidentally. this was when i thought of using config files but didn't know msdn supplied some so i coded my own too. mainly is a string parser then you sort of 'tokenise' the contents that you read. pain in the ass considering i did it in asm
why do you not think embedding settings would be useful.. when you take the program to another machine no need to worry about copying a config file or redoing configurations or copying registry keys. just 1 file copy
|
|
| Back to top |
|
 |
Pro-surf Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Dec 2007 Posts: 1415 Location: Under Ur Bed , Moauahauha
|
Posted: Sun Aug 02, 2009 6:35 am Post subject: |
|
|
I also got it to work ..
thanks
_________________
ProsTrain VIP |..........| - 80% Done im close to the finish line
 |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
|
| Back to top |
|
 |
Pro-surf Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Dec 2007 Posts: 1415 Location: Under Ur Bed , Moauahauha
|
Posted: Mon Aug 03, 2009 2:57 pm Post subject: |
|
|
Guys im having another problem..
when im trying to read if the checkbox is ticked or not it wont work..
| Quote: | TCHAR inBuf[80];
GetPrivateProfileStringA("ExtraHacks","SSFly","FALSE",inBuf,80,"C:\\ProSettings.ini");
if(inBuf == FALSE){
SendMessage (GetDlgItem(hWnd, IDC_CHECKBOX1), BM_SETCHECK, FALSE,0);
}
else{
SendMessage (GetDlgItem(hWnd, IDC_CHECKBOX1), BM_SETCHECK, TRUE,0);
} |
That code makes the checkbox true everytime even when the file says its false..
probably the "if" failes so..
how do i fix it?
_________________
ProsTrain VIP |..........| - 80% Done im close to the finish line
 |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Mon Aug 03, 2009 7:13 pm Post subject: |
|
|
FALSE is a typedef for 0
step through in the debugger so you can see that inBuf is actually getting the value you expect it to be.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Tue Aug 04, 2009 1:34 am Post subject: |
|
|
couldn't you just do this ?
| Code: | | SendMessage (GetDlgItem(hWnd, IDC_CHECKBOX1), BM_SETCHECK, GetPrivateProfileStringA("ExtraHacks","SSFly","FALSE",inBuf,80,"C:\\ProSettings.ini"),0); |
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Aug 04, 2009 2:07 am Post subject: |
|
|
| Slugsnack wrote: | couldn't you just do this ?
| Code: | | SendMessage (GetDlgItem(hWnd, IDC_CHECKBOX1), BM_SETCHECK, GetPrivateProfileStringA("ExtraHacks","SSFly","FALSE",inBuf,80,"C:\\ProSettings.ini"),0); |
|
GetPrivateProfileString returns a DWORD, the number of characters copied.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Tue Aug 04, 2009 2:18 am Post subject: |
|
|
| oh misread. thought the IF condition was for the return of that call
|
|
| Back to top |
|
 |
Pro-surf Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Dec 2007 Posts: 1415 Location: Under Ur Bed , Moauahauha
|
Posted: Tue Aug 04, 2009 2:08 pm Post subject: |
|
|
i dont get it
everything failes
i tried comparing inBuf to 0 , "0" , "FALSE", false(error) , FALSE
everything fucking failes man..
btw i checked and the function returns FALSE / TRUE
no 0 or 1
so what am i suppost to do
_________________
ProsTrain VIP |..........| - 80% Done im close to the finish line
 |
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Tue Aug 04, 2009 2:17 pm Post subject: |
|
|
| Pro-surf wrote: | i dont get it
everything failes
i tried comparing inBuf to 0 , "0" , "FALSE", false(error) , FALSE
everything fucking failes man..
btw i checked and the function returns FALSE / TRUE
no 0 or 1
so what am i suppost to do |
You can't compare inBuf to "0", it is just a pointer..try copying a string to it, then strcmp to the string you set.
Also, why would you compare the return to 0 or 1 ? Someone just stated that it returns the number of characters copied, so only compare to 0 for failure.
Also, why aren't you using GetPrivateProfileInt ? That seems like a more logical idea than string comparison.
|
|
| Back to top |
|
 |
Pro-surf Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Dec 2007 Posts: 1415 Location: Under Ur Bed , Moauahauha
|
Posted: Tue Aug 04, 2009 2:36 pm Post subject: |
|
|
| smartz993 wrote: | | Pro-surf wrote: | i dont get it
everything failes
i tried comparing inBuf to 0 , "0" , "FALSE", false(error) , FALSE
everything fucking failes man..
btw i checked and the function returns FALSE / TRUE
no 0 or 1
so what am i suppost to do |
You can't compare inBuf to "0", it is just a pointer..try copying a string to it, then strcmp to the string you set.
Also, why would you compare the return to 0 or 1 ? Someone just stated that it returns the number of characters copied, so only compare to 0 for failure.
Also, why aren't you using GetPrivateProfileInt ? That seems like a more logical idea than string comparison. |
I didnt compare it with 1 or 0
i tried FALSE TRUE which is the same i guess
ill try an Int this time..
EDIT :
man it works ..
you are good
btw didnt hear from you long time
thanks for the help man
EDIT2 :
thats how iv done it if anyone needs it :
| Quote: | BOOL outBuf = GetPrivateProfileInt("ExtraHacks","SSFly",0,"C:\\ProSettings.ini");
if(outBuf == 1){
SendMessage (GetDlgItem(hWnd, IDC_CHECKBOX1), BM_SETCHECK, TRUE,0);
}
else if(outBuf == 0){
SendMessage (GetDlgItem(hWnd, IDC_CHECKBOX1), BM_SETCHECK, FALSE,0); |
_________________
ProsTrain VIP |..........| - 80% Done im close to the finish line
 |
|
| Back to top |
|
 |
|