   INI files
  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?  
  unless you give the ini filename as a fullpath, the ini will be created/used from/in the "Windows" directory. you need to build up your ini filename so that it includes a fullpath. try using GetCurrentDirectory or GetModuleFileName as a starting point.  ;  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];  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.    ;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;  of course i was correct. i wouldn''t have posted unless i knew what i was talking about.  is there a basic assumption on these forums that APs aren''t believable? sorry, just curious if i should stop posting under AP so much.anyway, all of this profile stuff harkens back to the days of 3.1, before the registry came into being. at that time, iirc, almost all inis were kept in the system directory, whether they were private inis or system inis.  ;  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.  ;  CraZeE, you''d think that would work, and it does in most cases, but unfortunately not all. that''s because the exe loader may switch directories on your app (via shortcut launching, for instance, that specifies a different working directory) so that the first "current directory" the app sees is not the directory the exe is in. for an exe directory ini i would suggest always using GetModuleFileName to build your ini fullpath. _splitpath and _makepath come in handy for this purpose.  ;  thanx for that correction AP. neva considered that shortcoming. guess i better go fix my code to make em more shortcut-frenly.. hehe.  ;  yeah, i learned that one the hard way. that''s why i never forget it. 