[Haskell-cafe] Haskell DLL crashes Excel

Andreas Marth Andreas-Haskell at gmx.net
Fri Sep 22 09:38:10 EDT 2006


Hi Kyra!

First thanks for your repeated responses.

I tried to use SysAllocString as suggested by you and Esa Ilari Vuokko.

Unfortuntly I get an error: "fake: undefined reference to
`SysAllocString at 4`"
from the linker if I use "stdcall" (wich I think I should use) or fake:
undefined reference to `SysAllocString`" if I use ccall.
I solved this with adding C:\WINNT\system32\oleaut32.dll to the files the
linker shold link.
Was that correct?
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



Added my function:

testL :: Int -> CString -> IO BSTR8
testL n cs = do s <- peekCString cs
                sysAllocString $ concat $ take n $ repeat s

foreign export stdcall testL :: Int -> CString -> IO BSTR8


> Use SysAllocString... family. Also, remember they (by convention) have
> to be released from the client side.
>
> Cheers,
> Kyra
>
 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?

Thanks a lot,
Andreas



More information about the Haskell-Cafe mailing list