GetPrivateProfileSection results are truncated
See original GitHub issueDescribe the bug
GetPrivateProfileSection
is used to return a section from an INI file.
Consider the following example
[Unicode]
Unicode=yes
[Version]
signature="$CHICAGO$"
Revision=1
I can call the GetPrivateProfileSection
function to return the contents of say the Version
section. The API returns the results in the following format
signature="$CHICAGO$"\0Revision=1\0\0
When the StringBuilder used in the PInvoke declaration encounters the first null character, it stops building the string, and the rest of the result is discarded.
What code is involved
string inf = "C:\temp\my.ini"
StringBuilder sectionData = new StringBuilder(32000);
var bytesFilled = Kernel32.GetPrivateProfileSection("Version", sectionData, 32000, inf);
// sectionData will now hold only the first element
Expected behavior All items should be available. Perhaps an array of strings is more appopriate.
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (9 by maintainers)
Top Results From Across the Web
GetPrivateProfileString problem - truncates result - vbCity
The contents of the ini file is dynamically populated by a select statement in the database. All is working fine, except that for...
Read more >GetPrivateProfileString without Trim?
I have a class that reads entries using GetPrivateProfileString. ... string will be truncated. const int capacity = 255; StringBuilder temp ...
Read more >How to fix truncated PowerShell output, even when I've ...
Pipe output to Format-Table commandlet, e.g. as follows: Get-ChildItem 'E:\' -Force -Recurse | Select-Object FullName | Format-Table - ...
Read more >GetPrivateProfileStringW function (winbase.h) - Win32 apps
The GetPrivateProfileStringW (Unicode) function (winbase.h) retrieves a string from the specified section in an initialization file.
Read more >Thread: [RESOLVED] INI Getprofilesection
I use the following code to read the keys and values under Run section. VB Code: GetPrivateProfileSection "Run", retstring, strbuffer, "win.ini".
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Would a wrapper class be a valuable addition to do something like the following?
Glad it is useful. I laid in bed stewing on the idea and it came together quickly the next morning.