How to generate a dll?
Hallo! I want to make my Haskell program usable from Visual Basic. What is the way to go? (I tried the way the user guide for ghc 6.4.2 describes but the resulting dll was not stable.) While I don't have any clues about language interoperation I guess it is a task that is done many times before. So I would appreciate any pointers. Thanks for any help, Andreas
Andreas, I am using a DLL generated by ghc 6.4.2 in combination with Visual C++ 2005. Some useful links: http://www.willus.com/mingw/yongweiwu_stdcall.html http://en.wikipedia.org/wiki/Name_mangling http://www.mingw.org/mingwfaq.shtml#faq-msvcdll What do you mean by "the resulting dll was not stable"? Michael Andreas Marth wrote:
Hallo!
I want to make my Haskell program usable from Visual Basic. What is the way to go? (I tried the way the user guide for ghc 6.4.2 describes but the resulting dll was not stable.) While I don't have any clues about language interoperation I guess it is a task that is done many times before. So I would appreciate any pointers.
Thanks for any help, Andreas
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
From: "Michael Marte" <marte@pms.informatik.uni-muenchen.de> To: "Andreas Marth" <Andreas-Haskell@gmx.net> Cc: <haskell@haskell.org> Sent: Wednesday, September 06, 2006 6:04 PM Subject: Re: [Haskell] How to generate a dll?
Andreas,
I am using a DLL generated by ghc 6.4.2 in combination with Visual C++ 2005. Some useful links:
http://www.willus.com/mingw/yongweiwu_stdcall.html
http://en.wikipedia.org/wiki/Name_mangling
http://www.mingw.org/mingwfaq.shtml#faq-msvcdll
What do you mean by "the resulting dll was not stable"?
Michael
I meant that the dll crashed Excel wenn I stopped the debugging mode and also if I used it in a VB-projekt it crahed that when stopped. This happend with DLLs which had a Bool or Int as return or were only a sub. If I tried to return a String (marshalled to CString) the dll just plain crashed when called. Thank you for the links. I am working through them and hope it will get better. Do I understand it right that I will get a dll that can be incorporated into VB but is not a com-dll or is it a com dll just by being able to be called from VB? Thanks, Andreas
On 9/7/06, Andreas Marth <Andreas-Haskell@gmx.net> wrote:
I meant that the dll crashed Excel wenn I stopped the debugging mode and also if I used it in a VB-projekt it crahed that when stopped.
Hi, Andreas! Try adding these lines to your DllMain: if (reason == DLL_PROCESS_DETACH) { shutdownHaskell(); return TRUE; }
If I tried to return a String (marshalled to CString) the dll just plain crashed when called. How exactly is it marshalled?
-- Tolik
Hi!
Hi, Andreas! Try adding these lines to your DllMain:
if (reason == DLL_PROCESS_DETACH) { shutdownHaskell(); return TRUE; }
This worked great. (At least with Excel. I didn't test it with the VB-Project yet.)
If I tried to return a String (marshalled to CString) the dll just plain crashed when called. How exactly is it marshalled?
At the moment the test program is: module Calculate where import Foreign.C.String foreign export stdcall calculate :: CString -> IO (CString) calculate :: CString -> IO (CString) calculate cs = do s <- peekCString cs newCString (reverse s) So the newCString does the marshalling. (At least I think so.) But if I call this in VBA it crashes Excel VBA code: Dim helper As String Private Declare Function calculate Lib "Calculate.dll" (ByVal x as String) As String Sub test () helper = calculate("Test") Debug.Print helper End Sub All really basic. Does anybody know why that does not work? Thanks for all the answers up to now. Andreas
-- Tolik _______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
Andreas Marth wrote:
But if I call this in VBA it crashes Excel
VBA code: Dim helper As String Private Declare Function calculate Lib "Calculate.dll" (ByVal x as String) As String
Sub test () helper = calculate("Test") Debug.Print helper End Sub
All really basic.
Does anybody know why that does not work?
Thanks for all the answers up to now.
Andreas
The 'helper' must be BSTR. Cheers, Kyra
Andreas, one more pointer: http://haskell.org/haskellwiki/GHC:FAQ#GHC_on_Windows Michael Andreas Marth wrote:
Hallo!
I want to make my Haskell program usable from Visual Basic. What is the way to go? (I tried the way the user guide for ghc 6.4.2 describes but the resulting dll was not stable.) While I don't have any clues about language interoperation I guess it is a task that is done many times before. So I would appreciate any pointers.
Thanks for any help, Andreas
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
participants (5)
-
Anatoly Zaretsky -
Andreas Marth -
Andreas Marth -
kyra -
Michael Marte