Jump to content

  • Log In with Google      Sign In   
  • Create Account

WritePrivateProfileStruct question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 george7378   Members   -  Reputation: 1291

Like
0Likes
Like

Posted 04 April 2013 - 01:47 PM

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!



Sponsor:

#2 Zipster   Crossbones+   -  Reputation: 886

Like
1Likes
Like

Posted 04 April 2013 - 01:51 PM

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, 04 April 2013 - 01:56 PM.


#3 george7378   Members   -  Reputation: 1291

Like
0Likes
Like

Posted 04 April 2013 - 02:37 PM

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



#4 rip-off   Moderators   -  Reputation: 8764

Like
0Likes
Like

Posted 04 April 2013 - 03:28 PM

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?



#5 george7378   Members   -  Reputation: 1291

Like
0Likes
Like

Posted 04 April 2013 - 04:13 PM

I just tried GetLastError and it returned zero...






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS