Re: [Haskell-cafe] FFI and Excel VBA
A while ago I built a Haskell DLL that had to be invoked from Excel. For some reason (I do not remember exactly why) it did not work directly, so I wrote a small wrapper DLL in C++ that invoked Haskell functions. The wrapper DLL was invoked by Excel via COM. As regards your example, the only thing that springs to my mind is: check that the calling convention is set correctly (that is, to stdcall instead of ccall). Cheers, Cyril 2007/6/19, Lewis-Sandy, Darrell [EMAIL PROTECTED]: I have finally gotten to the point where my dll compiles (there is a missing space in the mainDll.h code at line 4:12) using GHC 6.6.1, and used the declare statement to expose the adder function in Excel VBA. My VBA Code is given below: Private Declare Function adder Lib adder.dll Alias [EMAIL PROTECTED] (ByVal x As Integer, ByVal y As Integer) As Integer Private Sub test() Debug.Print adder(1, 2) End Sub My problem is this: The function works fine (the immediate window displays 3), but when I terminate Excel, I get an application error (The instruction at … referenced memory at … . The memory could not be read.). Does anyone else have any experience calling Haskell from VBA that might be relevant? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] CUFP website
I noticed recently that the website of CUFP conference (Commercial Uses of Function Programming), which used to be at http://www.galois.com/cufp, is not accessible anymore. Does anybody know where it moved? Cyril ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell DLL crashes Excel
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 ___ Excel2Haskell.tar.bz2 Description: Binary data ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Creating DLLs with GHC
Matthew, As regards the symbols that end with _closure, I believe you can resolve them by adding -package parsec to the ghc command line (as far as I can see, all the symbols you list come from the parsec package). I don't know, though, what to do with the undefined symbols from matrixstack. You can try to check two things: 1) That the options you specify with -optl really reach the linker (e.g. try to give a non-existent library in -optl option and see if it complains). 2) That matrixstack.lib is understood by the linker (that is, it must be created with dlltool) 3) That the symbols it is looking for do exist in matrixstack.lib (you can check it with objdump, for instance). Cheers, Cyril ___ Matthew Bromberg wrote: ghc --mk-dll -o netsim.dll ExternLib.o ExternLib_stub.o dllNet.o src1.o src1_stub.o src2.o -optl-lmatrixstack -optl-L. My external C library is in matrixstack.dll and it has a corresponding static link stub library matrixstack.lib in the same directory as all the sources. It has references in one of the sources (say src1.hs). Unfortunately I get a host of undefined references to basically all the functions in matrixstack.dll and also some undefined references of the form Parsefile.o:ghc2996_0.hc:(.text+0x130): undefined reference to `TextziParserCombinatorsziParsecziError_show_closure' ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell DLL crashes Excel
Nikunj, The symptoms that you describe hint at some incorrect pointer handling. I believe the culprit is that pesky BSTR. I will try to dig up the code that I wrote a while ago to pass a BSTR to Haskell. Meanwhile, another hint. The GHC FAQ 1.4.1 says: For utterly horrible reasons, programs that use more than 128Mb of heap won't work when compiled dynamically on Windows (they should be fine statically compiled). (See http://haskell.org/haskellwiki/GHC:FAQ#My_program_that_uses_a_really_large_heap_crashes_on_Windows.) I have no clue what those horrible reasons might be, but you can limit the heap used by the Haskell DLL by setting the environment variable GHCRTS=-M128m Regards, Cyril ___ | From: Gupta, Nikunj (London) [mailto:[EMAIL PROTECTED] | Sent: 25 September 2006 10:31 | To: Simon Peyton-Jones | Subject: RE: [Haskell-cafe] Haskell DLL crashes Excel | | Hello Simon, | | Nice to hear from you. I haven't really been working with Haskell but I | posted the message to that list since that was the only list I was able | to locate even remotely referring to the problem I was facing. | I have a c++ code which I try to compile as a dll. When debugging the | code works fine but as soon as I compile it for release and launch an | independent process not attached to VC++ it crashes. Do you have any | suggestions with regards to the project settings that might be causing | the same. | | Any sort of help would be much appreciated | Regards | Nikunj ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskel DLL crashes Excel
Andreas Marth wrote: As you might now already know I try to let VBA call Haskell via a DLL. I had to do this a while ago; the best I could come up with was: 1. Make a Haskell DLL that exports plain C-style interface. 2. With Visual Studio, make a COM DLL that exports the interfaces to be used by VBA and passes the calls to the Haskell DLL. This COM DLL, among other things, handles the conversion between C-style strings and BSTR (there are examples on msdn.microsoft.com of doing this). Hope this helps. Cheers, Cyril ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe