• 13
• 16
• 27
• 9
• 9

WritePrivateProfileStruct question

This topic is 1809 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi everyone,

I'm using the WritePrivateProfileStruct function to work with .ini files for my game, and I have a quick question. This is how I've implemented it:

WritePrivateProfileStruct("Section", "Key", &Data, -1, "settings.ini");


Here, Data is an int. I sort of guessed the third and fourth parameters - is it OK to use it like I did, or should I do it differently? The function asks for an LPVOID for the third parameter - is it OK for my to provide a pointer to my int as I have done? I can't find any other examples out there so I don't know if I've done it right or not.

Thanks!

Share on other sites

You can specify any data you'd like, including just a single integer. However the fourth parameter is supposed to be the size of the data, which you've specified as -1, that when cast to an unsigned integer is actually ~4.2 billion bytes, a bit more than the data you've specified ;) You should use sizeof(int) instead, which is the true size of the data (a single integer).

Alternatively, for just a single integer, you could use WritePrivateProfileString instead and encode the integer as a string. Or you could use the registry... there's a number of different options, so you're not locked into using a raw data interface for profile settings.

Edited by Zipster

Share on other sites

Hey - ok, thanks! I tried a few things and for some reason it always returns zero and fails no matter what I do...

Share on other sites

I am not familiar with the function, but the documentation says:

If the function fails, or if it flushes the cached version of the most recently accessed initialization file, the return value is zero. To get extended error information, call GetLastError.

So, what does GetLastError() tell you?