
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? Nope. 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.