-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetPrivateProfileSection results are truncated #172
Comments
The values are there, but you have to know a little trick to extract them: |
…allocated memory for multistring results (#172)
I just added overloads to those methods that take an string inf = @"C:\temp\my.ini";
var chars = 32,767;
using var mem = new SafeCoTaskMemHandle(chars * StringHelper.GetCharSize());
var bytesFilled = Kernel32.GetPrivateProfileSection("Version", mem, chars, inf);
return mem.ToStringEnum(); If you'd like to try this before the next release, you can check the project home page for info on the AppVeyor prerelease NuGet feed. |
Brilliant. That is working great, thanks David. Was I doing something wrong with the StringBuilder? |
No. It appears that different versions of .NET handle StringBuilder internals differently. I'm actually working on some better wrappers so you can simply call : |
Would a wrapper class be a valuable addition to do something like the following? var ini = new InitializationFile(@"C:\temp\my.ini");
var versionSettings = ini.Sections["Version"];
foreach (var keyValuePair in versionSettings)
Console.WriteLine($"{keyValuePair.Key}={keyValuePair.Value}");
versionSettings["MyNewKey"] = "some value"; |
I just added one to the AppVeyor build. Look for |
Yeah thats an awesome idea. I turned to the API because most other parsers are regex or similarly based and I didn't feel comfortable with that. I'll convert my code over to use this and let you know how it goes |
Is it in the Vanara.PInvoke.Kernel32 package? I'm not seeing an updated version on AppVeyor. |
Yes. I got confirmation of the build a few minutes ago. |
Sometimes VS has a hard time updating packages whose version didn't change. You may need to flush your NuGet caches. |
Released! |
Sorry - late on the feedback, but I have used it and it is working well. Great idea. Thanks again David. |
Glad it is useful. I laid in bed stewing on the idea and it came together quickly the next morning. |
Describe the bug
GetPrivateProfileSection
is used to return a section from an INI file.Consider the following example
I can call the
GetPrivateProfileSection
function to return the contents of say theVersion
section. The API returns the results in the following formatsignature="$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
Expected behavior
All items should be available. Perhaps an array of strings is more appopriate.
The text was updated successfully, but these errors were encountered: