[Haskell-cafe] Haskell DLL crashes Excel

Kyra kyra at veernet.ru
Fri Sep 22 11:21:30 EDT 2006

Andreas Marth wrote:
> I solved this with adding C:\WINNT\system32\oleaut32.dll to the files the
> linker shold link.
> Was that correct?
I prefer "-loleaut32" but see no big difference.

> Because this dll crashes Excel instantly. I used the code suggested by Esa
> Ilari Vuokko:
> newtype BSTR = BSTR CWString
> foreign import stdcall "oleauto.h SysAllocString" c_SysAllocString ::
> CWString -> IO BSTR
> sysAllocString :: String -> IO BSTR
> sysAllocString s = withCWString s c_SysAllocString >>= return
Have You made your code working with no crash?
Remark: ">>= return" is extraneous (but absolutely harmless) here

>  Regarding the release from the client side:
> If I call a Haskell DLL from Excel shall I release the BSTR within the
> Haskell DLL?
> That would mean before the value is returned?
The rule is: if You receive some BSTR from the outside world You must 
release it, if You allocate some BSTR and return it to the outside 
world, it's the outside world's responsibility to release it.

More information about the Haskell-Cafe mailing list