Posts

Showing posts from February, 2009

MFC reading from a .ini file

Recently I came across a need to read from an .ini file for an MFC application I'm working on. Now some might say why even bother using an .ini file, that's what the registry is for douchebag! Well I need something that a user can easily edit and store 3 small values and creating screens/forms to read/write to the registry doesn't interest me too much. So a simple ini file will do the trick. I found the perfect function is GetPrivatProfileString I however ran into some issues using this function. It's a win32 function and I'm using it in an MFC based application with CStrings. The function itself is expecting LPWSTR parameters so I thought by using the CString.GetBuffer method this would work. But I found this eventually will run you out of stack memory and cause exceptions. This even after using the ReleaseBuffer method that MSDN tells us to call after using GetBuffer. So in order to read all the values I needed from the file I found I had to read in LPWST