1. c peek string problem

------=_NextPart_000_000A_01BF9BEF.3A37FCE0
        charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable

i am trying to get string 'szMessage' at memory location 'iszMessage', =
but cant
Function gives: len=3D31, but szMessage is one strange character.


here is code:

global function GetLastErrorFormated()
=20
 sequence szMessage
 atom iszMessage
 atom hr,len

 iszMessage=3D allocate(80)

 hr=3Dc_func(iGetLastError,{})=20
    =20
    len=3DFormatMessage(
        or_all({FORMAT_MESSAGE_ALLOCATE_BUFFER,
        FORMAT_MESSAGE_FROM_SYSTEM}),
        NULL,
        hr,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), --//The user default =
language
        iszMessage,
        0,
        NULL )

 szMessage=3D{}
 if len then
  szMessage=3Dpeek({iszMessage,len})
  msgbox(sprintf("%s%s%s%d%s%d",
  {"szMessage=3D",szMessage,", len=3D",len,       -- says len=3D32
  ", iszMessage=3D",iszMessage           --says iszMessage=3D7405344
  })) =20
 end if =20
   =20
 free(iszMessage)
     =20
 return szMessage
end function

------=_NextPart_000_000A_01BF9BEF.3A37FCE0
        charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-2" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3401" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>i am trying to get string 'szMessage' =
at memory=20
location 'iszMessage', but cant</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Function gives: len=3D31, but szMessage =
is one=20
strange character.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>here is code:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>global function=20
GetLastErrorFormated()<BR>&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;sequence szMessage<BR>&nbsp;atom=20
iszMessage<BR>&nbsp;atom hr,len</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;iszMessage=3D =
allocate(80)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;=20
p;=20
hr,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
MAKELANGID(LANG_NEUTRAL,=20
SUBLANG_DEFAULT), --//The user default=20
0,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL )</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;szMessage=3D{}<BR>&nbsp;if len=20
len=3D",len,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- says =
len=3D32<BR>&nbsp;&nbsp;",=20
&nbsp;&nbsp;=20
--says iszMessage=3D7405344<BR>&nbsp;&nbsp;}))&nbsp;&nbsp;<BR>&nbsp;end=20
if&nbsp;&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial=20
p;&nbsp;&nbsp;&nbsp;=20

------=_NextPart_000_000A_01BF9BEF.3A37FCE0--

new topic     » topic index » view message » categorize

2. Re: c peek string problem

global function GetLastErrorFormated()

 sequence szMessage
 atom iszMessage
 atom hr,len

 iszMessage= allocate(80)

 hr=c_func(iGetLastError,{})

    len=FormatMessage(
        or_all({FORMAT_MESSAGE_ALLOCATE_BUFFER,
        FORMAT_MESSAGE_FROM_SYSTEM}),
        NULL,
        hr,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), --//The user default
language
        iszMessage,
        0,
        NULL )

 szMessage={}

---------------------------------
-- you need to convert memory string into a sequence
-- add this code which converts the memory
-- string into a sequence

 sequence TheMessage
 integer char
 atom mem_addr

 mem_addr = iszMessage
 TheMessage = ""
 if len then
   char = peek(mem_addr)
   while char do          --  <<------- watchs for zero termination
     TheMessage = append(TheMessage, char) -- builds the sequence
     mem_addr += 1
     char = peek(mem_addr)
   end while
 end if

-- then change your code to print
-- TheMessage sequence below with a %s in the msgbox
---------------------------------

  szMessage=peek({iszMessage,len})
  msgbox(sprintf("%s%s%s%d%s%d",
  {"szMessage=",szMessage,", len=",len,       -- says len=32
  ", iszMessage=",iszMessage           --says iszMessage=7405344
  }))
 end if

 free(iszMessage)

 return szMessage
end function

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu