NO

Author Topic: GetPrivateProfileString  (Read 972 times)

Offline HellOfMice

  • Member
  • *
  • Posts: 254
  • Never be pleased, always improve
Re: GetPrivateProfileString
« Reply #15 on: December 16, 2024, 04:26:44 PM »
Hi John,


I had a normal time in my bed but did not slept very much...


I am ok with all your sentences. I had not understood. Sorry.


Philippe
--------------------------------
Kenavo

Offline HellOfMice

  • Member
  • *
  • Posts: 254
  • Never be pleased, always improve
Re: GetPrivateProfileString
« Reply #16 on: December 16, 2024, 04:31:26 PM »
From Microsoft
Quote
[in] lpDefault A default string. If the lpKeyName key cannot be found in the initialization file, GetPrivateProfileString copies the default string to the lpReturnedString buffer.If this parameter is NULL, the default is an empty string, "".Avoid specifying a default string with trailing blank characters. The function inserts a null character in the lpReturnedString buffer to strip any trailing blanks.


They don't say that the returned string has an empty string if lpKeyName has no value after '='
« Last Edit: December 16, 2024, 04:34:21 PM by HellOfMice »
--------------------------------
Kenavo

Offline John Z

  • Member
  • *
  • Posts: 934
Re: GetPrivateProfileString
« Reply #17 on: December 16, 2024, 04:36:40 PM »
We are in sync!  Too little sleep! :(

A default string. If the lpKeyName key cannot be found in the initialization file, GetPrivateProfileString copies the default string to the lpReturnedString buffer.If this parameter is NULL, the default is an empty string, Avoid specifying a default string with trailing blank characters. The function inserts a null character in the lpReturnedString buffer to strip any trailing blanks.


This is case #1 ....

Yes MS never clearly discusses case #3

Cheers,
John Z
« Last Edit: December 16, 2024, 04:55:26 PM by John Z »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2160
Re: GetPrivateProfileString
« Reply #18 on: December 16, 2024, 05:07:18 PM »
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>

int __cdecl main(void)
{
char szBuf[260];
DWORD rc = GetPrivateProfileString("Dialog Box #3", "Dialog Menu ID", "0", szBuf, sizeof(szBuf), "./GetPrivate.ini");
DWORD ec = GetLastError();
printf("%d, %d, '%s'\n", ec, rc, szBuf);
rc = GetPrivateProfileString("Dialog Box #3", "Dialog Menu IDs", NULL, szBuf, sizeof(szBuf), "./GetPrivate.ini");
ec = GetLastError();
printf("%d, %d, '%s'\n", ec, rc, szBuf);
return 0;
}
Code: [Select]
[Dialog Box #3]
Dialog Menu ID=
Code: [Select]
0, 0, ''
2, 0, ''
May the source be with you

Offline John Z

  • Member
  • *
  • Posts: 934
Re: GetPrivateProfileString
« Reply #19 on: December 16, 2024, 07:24:18 PM »
Excellent as usual TimoVJL!

John Z