[Haskell-cafe] Re: Haskell DLL crashes Excel

Cyril Schmidt cschmidt at deds.nl
Tue Sep 26 18:16:39 EDT 2006


A few people recently asked how to pass a string between a Haskell DLL 
and Excel.
I attach the proof-of-concept code that I wrote a while ago; it 
demonstrates passing
a string from Excel to Haskell and the other way. Most of the C++ code 
is taken
from code examples at http://msdn.microsoft.com

Beware, though, that the code has never been thoroughly tested. I ran 
it, and it did not
crash -- that's almost all I can say. I even do not know if it leaks any 
memory. Use it
at your own peril.

The tar file contains a sample Excel sheet, and the sources of two DLLs: 
a COM DLL
which interfaces with Excel, and a Haskell DLL which is invoked by the 
COM DLL.
You will need Visual Studio 7.1 to build the COM DLL.

The Haskell DLL exports one function, hString2String, which takes a 
C-style string,
and returns the reverse of it.

To build the Haskell DLL, run build.bat.
To build (and register) the COM DLL, open Excel2Haskell.sln in Visual 
Studio, and hit Build.
Once the two libraries are built, open Worksheet.xls and see how the 
function is invoked.

Note that the COM DLL can be used not only by Excel, but by any other 
program or script that
understands COM. For example, VBA scripts in Word, or VB and Javascript 
run by Wscript or
Cscript.

Hope this helps.

Regards,

Cyril
___

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Excel2Haskell.tar.bz2
Type: application/octet-stream
Size: 15489 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20060927/416b8e0b/Excel2Haskell.tar-0001.obj


More information about the Haskell-Cafe mailing list