I'm having problems getting the spaces at the end of a string value from an ini file.

For example:


String1=This is string one with 5 spaces after it.

It stops at the period, anyone know why or how to solve the problem? :X

Heres a simple test I threw.

>> test.asm

.486
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\macros\macros.asm
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib

.data

.data?
hInstance HINSTANCE ?
buffer db 2000 dup(?)

.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax

invoke GetPrivateProfileString,SADD("Test"),SADD("test"),NULL,addr buffer,1024,SADD("D:\test.ini")
invoke MessageBox,NULL,addr buffer,addr buffer,MB_OK

invoke ExitProcess,eax
end start

>> D:\test.ini

testbegin=xxx
test=testing...
testend=xxx
Posted on 2003-07-12 16:40:36 by xkardisx
MSDN:

GetPrivateProfileString copies the default string to the lpReturnedString buffer. This parameter cannot be NULL.

Avoid specifying a default string with trailing blank characters. The function inserts a null character in the lpReturnedString buffer to strip any trailing blanks.

:(

What's a way to work around this, or do I have to create my own INI parser?
Posted on 2003-07-12 16:42:26 by xkardisx
Here is an idea for a work-around.

Say you have a key like this:


String1=This is string one with 5 spaces after it.

Instead of the expecting spaces use _ Underscores.
Somthing that wont normally occur in the string.

Like:

String1=This is string one with 5 spaces after it. _____

When you retrieve the string convert the underscores (or whatever)
to spaces.

I did something like this is a keyword file that made the user specify the actual
number of spaces in a more descriptive way. like....

_This_is_line__._

So they were always aware the actual space count.

This method has a bit of a hack feel.

btw, writing your own ini parser isn't that difficult.

RobotBob
Posted on 2003-07-12 22:03:46 by RobotBob
Oh I know its not hard. I just didn't want to, as I have other important thing to work out in the meantime. The reason I don't want to use _ or a temporary *, because basically my program uses an existing INI file that was generated by another program. That program (not made by me), probably uses its own INI routine because it reads the space. I want the INI to be able to work properly in both programs. :)
Posted on 2003-07-13 00:07:49 by xkardisx
Oh, If someone else doesn't think of another work-around and
you are forced to write your own ini parser...
Since you are crunched for time maybe some else here has a ready to go
ini parser you can use.

Good luck

RobotBob
Posted on 2003-07-13 00:15:32 by RobotBob
There is no workaround, using another character in place of the space can cause problems if you don't directly control the entries. Write a section parser using GetPrivateProfileSection to load the strings into a NULL terminated array. It is simply a matter of scanning forward for a '=' token and comparing values. Note that you are limited to 32767 characters in the buffer to load the section, that must be the maximum value you pass to the function as a buffer size as well.
Posted on 2003-07-13 00:35:09 by donkey