Sign in to follow this  
george7378

WritePrivateProfileStruct question

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 this post


Link to post
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 this post


Link to post
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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this