Hi all,<br><br>I'm trying to make RFC calls to SAP using the nwsaprfc library. Some structs defined in the library contains arrays (byte or word arrays). For example:<br><br>typedef struct _RFC_ATTRIBUTES<br>{<br> SAP_UC dest[64+1]; /* RFC destination */<br>
SAP_UC host[100+1]; /* Own host name */<br> SAP_UC partnerHost[100+1]; /* Partner host name */<br> SAP_UC sysNumber[2+1]; /* R/3 system number */<br>
SAP_UC sysId[8+1]; /* R/3 system name */<br> SAP_UC client[3+1]; /* Client */<br> SAP_UC user[12+1]; /* User */<br>
SAP_UC language[2+1]; /* Language */<br> ... continued<br>}}RFC_ATTRIBUTES, *P_RFC_ATTRIBUTES;<br><br>I would like to create a Haskell Storable counterpart of this structure. Using <a href="http://therning.org/magnus/archives/tag/hsc2hs">http://therning.org/magnus/archives/tag/hsc2hs</a> as an starting point, I could create Storable for structures containing fields with basic types.<br>
<br>Before working on the real data structures I wrote a more simple example to play with:<br><br>-- File: ArrayStruct.h --<br>typedef struct _ArrayStruct<br>{<br> char a[10+1];<br> char b[20+1];<br> char c[30+1];<br>
} ArrayStruct, *P_ArrayStruct;<br><br>-- File: ArrayStruct.c --<br>#include "ArrayStruct.h"<br><br>void<br>print_array_struct(ArrayStruct *f)<br>{<br> printf("%s\n", __FUNCTION__);<br> printf("f->a: %s\n", f->a);<br>
printf("f->b: %s\n", f->b);<br> printf("f->c: %s\n", f->c);<br>}<br><br>-- File: HArrayStruct.hsc<br>{-# OPTIONS -ffi #-}<br>module Main<br> where<br><br>import Foreign<br>import Foreign.C.Types<br>
<br>#include "ArrayStruct.h"<br><br>data HArrayStruct = HArrayStruct { a :: String, b :: String, c :: String }<br>type HarrayStructPtr = Ptr HArrayStruct<br><br>foreign import ccall "static ArrayStruct.h print_array_struct"<br>
f_print_array_struct :: ArrayStructPtr -> IO ()<br><br>instance Storable HArrayStruct where<br> sizeOf _ = (#size ArrayStruct)<br> alignment _ = alignment (undefined :: CInt)<br> peek _ = error "peek is not implemented"<br>
poke ptr (HArrayStruct a' b' c') = do<br> (#poke ArrayStruct, a) ptr a'<br> (#poke ArrayStruct, b) ptr b'<br> (#poke ArrayStruct, c) ptr c'<br><br>printArrayStruct as = with as f_print_array_struct<br>
<br>main = printArrayStruct $ HArrayStruct { a="some", b="test", c="data" }<br><br>-- End of files<br><br>Of course it won't work as HArrayStruct in file HArrayStruct.hs uses Strings and String is not an instance of Storable.<br>
<br>Ideally I would need some sort of Storable array of char. Is Data.Storable.Array the type I'm looking for? Could someone point me to some code using the same kind of structures?<br><br>Thanks,<br><br>Olivier.<br>