1. GetPrivateProfileString API call

I need some help with the following test file. Everything works except
when I call the next to last line in the file:
  o = ReadPvtIni("Dirs", "BatDir", "C:\\Compid.ini")

The section, key and file names are correct. In the function,
ReadPvtIni, Rtn should receive the length of the string returned in
ptrRtnBuf. Rtn receives 0 from the call to c_func(), indicating that it
is not returning anything. Thus "ERROR" is returned in this example.
What have I done wrong?

Also, once I get the key value returned in ptrRtnBuf, how do I convert
it back to a normal sequence (string) so that I can return it instead of
"OKAY".

There are several things, such as the test on Rtn, that are not final.
They exist just for this test. But I can't get the basic test of
ReadPvtIni() to work.

Thanks in advance for any help.


---- IniTest.exw

include dll.e
include machine.e
include misc.e
include get.e

with trace

atom
  User32,
  Kernel32

integer
  MbId,
  GpId

object o

User32 = open_dll("user32.dll")
Kernel32 = open_dll("kernel32.dll")


procedure Mb(sequence Text, sequence Title, object Style)
  atom ptrText, ptrTitle
  integer orStyle
  object o

  ptrText = allocate_string(Text)
  ptrTitle = allocate_string(Title)
  orStyle = Style
  o = c_func(MbId,{NULL, ptrText, ptrTitle, orStyle})
  free(ptrText)
  free(ptrTitle)
end procedure --Mb

procedure ErrId(sequence Msg)
  Mb(Msg, "Error getting Id", 0)
  abort(1)
end procedure --ErrId

MbId = define_c_func(User32, "MessageBoxA", {C_POINTER, C_POINTER,
C_POINTER, C_INT}, C_INT)
if MbId = -1 then ErrId("MbId") end if

GpId = define_c_func(Kernel32, "GetPrivateProfileStringA", {C_POINTER,
C_POINTER, C_POINTER, C_POINTER, C_DOUBLE, C_POINTER}, C_INT)
if GpId = -1 then ErrId("GpId") end if

function ReadPvtIni(sequence Section, sequence Key, sequence IniFile)
  atom
    ptrSection,
    ptrKey,
    ptrDefVal,
    ptrRtnBuf,
    ptrIniFile
  integer
    RtnBufLen,
    Rtn

  RtnBufLen = 255

  ptrSection = allocate_string(Section)
  ptrKey = allocate_string(Key)
  ptrDefVal = allocate_string("NOTFOUND")
  ptrRtnBuf = allocate_string(repeat(' ', RtnBufLen))
  ptrIniFile = allocate_string(IniFile)

  Rtn = c_func(GpId,{ptrSection, ptrKey, ptrDefVal, ptrRtnBuf,
RtnBufLen, ptrIniFile})
  if Rtn < 1 then
    return "ERROR"
  else
    return "OKAY"
  end if
end function --ReadPvtIni

o = ReadPvtIni("Dirs", "BatDir", "C:\\Compid.ini")
Mb(o,"Ini", 0)


--
Terry Constant
constant at flash.net

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu