[Haskell-cafe] Why am I not allowed to use CStringLen
inforeignexport?
Brian Hulley
brianh at metamilk.com
Fri Sep 22 13:03:01 EDT 2006
Andreas Marth wrote:
> Thanks a lot for this information it helped a lot.
Glad to be of help.
> I am thinking about creating a wikipage about Haskell<->VBA
> interfacing through a DLL.
> Is it okay for you if I put your code there?
Yes.
> I am a bit concerned about the memory. newArray states that the
> memory has to be freed after usage. Is this needed here? How can it
> be done?
One way could be to write a function which creates the BSTR, passes it to a
function, then deallocates the BSTR before returning eg (untested):
import Control.Exception (bracket)
withBSTR8 :: [Char] -> (BSTR8 -> IO a) -> IO a
withBSTR8 s f =
bracket
(createBSTR8 s)
(\bstr -> free (bstr `plusPtr` (-4)))
(\bstr -> f bstr)
Regards, Brian.
--
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.
http://www.metamilk.com
More information about the Haskell-Cafe
mailing list