Skip to main content
GameDev.net gamedev.net
🔒 Locked

INI files

Started by The Heretic Jan 2, 2003 at 7:30 AM 9 replies 600+ views
Original Post
The Heretic
The Heretic
What is wrong with my code?
#include <iostream>
#include <windows.h>
#include <winsock.h>

int main(int argc, char **argv)
{
     int useINI = GetPrivateProfileInt("defaults", "useDefaults", 300, "chat.ini");
     cout << useINI << endl;
} 
and chat.ini
[defaults]
useDefaults=1
 
and it give me 300! Whats with it?
Red Ghost
Red Ghost
UseIni contains 300 because the function does not seem to find the file/section and key.
There isn't much to do from here:
I would suggest to check if the ini file is in the same directory than your program.
Hope that helps.
Ghostly yours,
Red.

Edit: removed wrong information. GetPrivateProfileInt is not case sensitive for the key and the section names.

[edited by - Red Ghost on January 2, 2003 8:47:10 AM]
Ghostly yours,Red.
CWizard
CWizard
I was a bit surprised that the function don''t seem to search the current directory. Therefor, the AP is correct; you need to specify the full path unless the ini-file is in the windows directory:
quote:
MSDN - GetPrivateProfileInt()
lpFileName
[in] Pointer to a null-terminated string that specifies the name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory.
It is unfortunate that the function has no way of telling if it was the file or the key that didn''t exist.


Crispy
Crispy
quote:
Original post by CWizard
I was a bit surprised that the function don''t seem to search the current directory.


Actually it''s pretty logical IMO. I bet finding "default.ini" or "init.ini" in both the exe folder as well as in the windows folder is not too uncommon and i for one wouldn''t be able to prefer one to the other. if you need to handle your ini stuff - write your own routines. so i wouldn''t say MS did "bad" or "wrong" with this one... then again, if you look at Windows 98 source code, there''s plenty of things to improve...

Crispy

"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
CraZeE
CraZeE
yup, GetPrivateProfile* require full path. But if u want to access an ini file relative to the binary files location, try this for the file path:

"./file_name" or "./directory_name/file_name"

its safer to use the forward slash coz the backslash requires the use of the escape character. Try it.
To learn, we share... Give some to take some -
CraZeE
CraZeE
thanx for that correction AP. neva considered that shortcoming. guess i better go fix my code to make em more shortcut-frenly.. hehe.
To learn, we share... Give some to take some -
CWizard
CWizard
quote:
Original post by Anonymous Poster
is there a basic assumption on these forums that APs aren''t believable?
I hope not, and I''m sorry if my support for your input came out that way.


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.