Andreas Marth wrote:

type BSTR8 = Ptr Word8

createBSTR8 :: String -> IO BSTR8
createBSTR8 s = do
   let
     len :: Word32 = fromIntegral (length s)
     low_l :: Word8 = fromIntegral (len .&. 0xFFFF)
     low_h :: Word8 = fromIntegral (shiftR len 8 .&. 0xFFFF)
     high_l :: Word8 = fromIntegral (shiftR len 16 .&. 0xFFFF)
     high_h :: Word8 = fromIntegral (shiftR len 24 .&. 0xFFFF)
   arr <- newArray ([low_l,low_h,high_l,high_h] ++ map (fromIntegral .
fromEnum) s ++ [0])
   return $! plusPtr arr 4

Use SysAllocString... family. Also, remember they (by convention) have to be released from the client side.

Cheers,
Kyra


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to