
Hello
Here the code I try to use
I get an array of (HklFactory *) via the GetAll method and I want to read for each of these HklFactory the name of the factory with the NameGet method.
-- data HklFactory
newtype HklFactory = HklFactory (Ptr HklFactory) deriving (Show, Storable)
hklFactoryGetAll :: IO [HklFactory]
hklFactoryGetAll = alloca $ \ptr -> do
factories <- c_hkl_factory_get_all ptr
n <- peek ptr
peekArray n factories
foreign import ccall unsafe "hkl.h hkl_factory_get_all"
c_hkl_factory_get_all :: Ptr Int
-> IO (Ptr HklFactory)
hklFactoryNameGet :: Ptr HklFactory
-> IO String
hklFactoryNameGet factory = do
name <- c_hkl_factory_name_get factory
peekCString name
foreign import ccall unsafe "hkl.h hkl_factory_name_get"
c_hkl_factory_name_get :: Ptr HklFactory
-> IO CString
main :: IO ()
main = do
initGUI
factories <- hklFactoryGetAll
names <- mapM hklFactoryNameGet factories
print factories
print names
the signature of the C method are:
typedef struct _HklFactory HklFactory;
HKLAPI HklFactory **hkl_factory_get_all(size_t *n) HKL_ARG_NONNULL(1);
HKLAPI const char *hkl_factory_name_get(const HklFactory *self) HKL_ARG_NONNULL(1);
when I run the haskell code, I just get garbage when I try to extract the name of all HklFActoies
here the output
[HklFactory 0xb777b920,HklFactory 0xb777ba6c,HklFactory 0xb777ba98,HklFactory 0xb777bac4,HklFactory 0xb777bbf8,HklFactory 0xb777bef8,HklFactory 0xb777c4f0,HklFactory 0xb777c524,HklFactory 0xb777c6c0,HklFactory 0xb777c784,HklFactory 0xb777c8a8,HklFactory 0xb777c8dc,HklFactory 0xb777c908,HklFactory 0xb777c9cc]
[",v+v