Exposing Haskell functions with string arguments in a DLL

Simon Marlow fldrsimonmar@microsoft.com
Mon, 16 Oct 2000 04:39:51 -0700


You can use CString.packString and CString.packStringIO, but be aware that 
	(a) these functions return ByteArrays, so you need to
	    adjust your foreign export definitions accordingly
	(b) because they use ByteArray, these functions are GHC
	    specific and any use of them is non-portable.

GHC currently doesn't supply a portable way to marshal strings from Haskell
to C.  However, you can quite easily write your own using eg. the functions
from Storable.

Cheers,
	Simon

> -----Original Message-----
> From: Lescher Christian [mailto:christian.lescher@icn.siemens.de]
> Sent: Monday, October 16, 2000 12:20 PM
> To: Simon Marlow; 'glasgow-haskell-users@haskell.org'
> Subject: AW: Exposing Haskell functions with string arguments in a DLL
> 
> 
> Thanks!! What about the other direction? (Haskell function 
> with string result)
> 
> Christian
> 
> > -----Urspr> üngliche Nachricht-----
> > Von:	Simon Marlow [SMTP:fldrsimonmar@microsoft.com]
> > Gesendet am:	Montag, 16. Oktober 2000 13:07
> > An:	'Lescher Christian'; 'glasgow-haskell-users@haskell.org'
> > Betreff:	RE: Exposing Haskell functions with string 
> arguments in a DLL
> > 
> > 
> > > How can I convert string arguments (null-terminated strings) 
> > > to Haskell's [Char]? I saw there is some CString module in 
> > > package lang of GHC, but I didn't found any documentation 
> > > about it (e.g. packStringIO...?).
> > 
> > For converting a static null-terminated C string to a 
> Haskell String, use
> > CString.unpackCString.  If you need to free the memory used 
> by the original
> > C string afterwards, use CString.unpackCStringIO.
> > 
> > Cheers,
> > 	Simon
>