• Welcome to Valhalla Legends Archive.
 

WritePrivateProfileString() is Evil

Started by R.a.B.B.i.T, July 06, 2005, 08:18 AM

Previous topic - Next topic

R.a.B.B.i.T

WPPS crashes my program whenever I try to use it with a path that has spaces in it.  Anyone know (and I know you DO) how to overcome this issue?

MyndFyre

Use the Registry.  WritePrivateProfileString is deprecated.

QuoteNote  This function is provided only for compatibility with 16-bit versions of Windows. Applications should store initialization information in the registry.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/writeprivateprofilestring.asp
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

R.a.B.B.i.T

I want people to be able to edit the values in the ini files without potentially raping their computer, though.

Also note that MSDN says:
QuoteApplications should store initialization information in the registry.
and what I want to store is configuration, not initialization, information.

UserLoser.

#3

char FileName[MAX_PATH + 1];
GetCurrentDirectory(MAX_PATH - sizeof("\\TestFile.txt"), FileName);
strcat(FileName, "\\TestFile.txt");
printf("FileName = %s\r\n", FileName);
printf("Return = %08x\r\n", WritePrivateProfileString("AppName", "KeyName", "String", FileName));
getch();


That works, now show us what you did so we can tell you how wrong you are (or show output from that if it doesn't work)

R.a.B.B.i.T

Before I was using GetConsoleLine(), trimming the program name, and adding on the file path I wanted to save to (I deleted this code).  It crashed, even when I manually set it to the same place (somewhere on my desktop), as opposed to having the program do that itself (so it wasn't me).  I searched Google for about 1.5 hours until I found I could just set the filepath to ".\\file.ini".  Thanks for your help, though (I forgot to say it was working).

That works, though.

MyndFyre

Note that that only works for an application -- running as a service sets the working directory to %SYSTEMROOT%\System32.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Adron

Quote from: rabbit on July 07, 2005, 03:59 PM
Before I was using GetConsoleLine(), trimming the program name, and adding on the file path I wanted to save to (I deleted this code).  It crashed, even when I manually set it to the same place (somewhere on my desktop), as opposed to having the program do that itself (so it wasn't me).  I searched Google for about 1.5 hours until I found I could just set the filepath to ".\\file.ini".  Thanks for your help, though (I forgot to say it was working).

That works, though.

Sounds like you didn't allocate sufficient space for the string...

R.a.B.B.i.T

//crashes
WritePrivateProfileString("appName", "keyName", "value", "D:\\Program Files\\file.ini");

//doesn't crash
WritePrivateProfileString("appName", "keyName", "value", "D:\\file.ini");


Even that was annoying.