1. c peek string problem
- Posted by =?iso-8859-2?B?qWtvZGE=?= <tone.skoda at SIOL.NET> Apr 01, 2000
- 461 views
------=_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> </DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>here is code:</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>global function=20 GetLastErrorFormated()<BR> </FONT></DIV> <DIV><FONT face=3DArial size=3D2> sequence szMessage<BR> atom=20 iszMessage<BR> atom hr,len</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> iszMessage=3D = allocate(80)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial=20 nbsp; <BR> =20 =20 p;=20 hr,<BR> = MAKELANGID(LANG_NEUTRAL,=20 SUBLANG_DEFAULT), --//The user default=20 0,<BR> NULL )</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> szMessage=3D{}<BR> if len=20 len=3D",len, -- says = len=3D32<BR> ",=20 =20 --says iszMessage=3D7405344<BR> })) <BR> end=20 if </FONT></DIV> <DIV><FONT face=3DArial=20 p; =20 ------=_NextPart_000_000A_01BF9BEF.3A37FCE0--
2. Re: c peek string problem
- Posted by Bernie Ryan <xotron at BUFFNET.NET> Apr 01, 2000
- 426 views
- Last edited Apr 02, 2000
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