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
|
Not Categorized, Please Help
|
|