Followers 0

WritePrivateProfileStruct question

4 posts in this topic

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!

0

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
1

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...

0

Share on other sites

I am not familiar with the function, but the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms725502(v=vs.85).aspx"]documentation[/url] 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?

0

Share on other sites

I just tried GetLastError and it returned zero...

0

Create an account

Register a new account