Sorry if I'm talking to myself, but I found a solution and thought it could be interesting for other people who need to call GHC created DLLs from Excel.<br><br>The solution is based on the information found in : <a href="http://haskell.org/haskellwiki/GHC/Using_the_FFI#Debugging_Haskell_DLLs">
http://haskell.org/haskellwiki/GHC/Using_the_FFI#Debugging_Haskell_DLLs</a>.<br><br>As suggested, I added two extra functions in my dllMain.c file (adder_Begin, adder_End) and removed the startupHaskell call from the dllMain function.
<br><br>adder_Begin contains the startupHaskell call and adder_End the shutdownHaskell. dllMain just returns true. I also adapted the Excel VBA code to call adder_Begin on a WorkBook_Open event and adder_End on a WorkBook_BeforeClose event.
<br><br>The VBA looks like this:<br><br>Public functions in a new "Module1" module (cannot declare Public functions in the ThisWorkbook module):<br><br><div style="margin-left: 40px;">Public Declare Function adder Lib "
adder.dll" Alias "adder@8" (ByVal x As Long, ByVal y As Long) As Long<br>Public Declare Function adder_Begin Lib "adder.dll" () As Boolean<br>Public Declare Sub adder_End Lib "adder.dll" ()
<br></div><br>Private functions the the "ThisWorkbook" module:<br><br><div style="margin-left: 40px;">Private Sub Workbook_BeforeClose(Cancel As Boolean)<br>adder_End<br>End Sub<br><br>Private Sub Workbook_Open()
<br>adder_Begin<br>End Sub<br></div><br>The GHC dllMain.c looks like this:<br><br><div style="margin-left: 40px;">#include <windows.h><br>#include <Rts.h><br><br>#define __ADDER_DLL_EXPORT<br>#define ADDER_API _declspec(dllexport)
<br><br>extern void __stginit_Adder(void);<br><br>static char* args[] = { "ghcDll", NULL };<br> /* N.B. argv arrays must end with NULL */<br><br>BOOL STDCALL DllMain( HANDLE hModule, <br> DWORD ul_reason_for_call,
<br> LPVOID lpReserved<br> ){<br> return TRUE;<br>}<br><br>ADDER_API BOOL adder_Begin(){<br> startupHaskell(1, args, __stginit_Adder);<br> return HS_BOOL_TRUE;<br>}<br><br>ADDER_API void adder_End(){
<br> shutdownHaskell();<br>}<br></div><br>If somebody wants the code and Excel file, just ask, I'll be happy to provide it.<br><br>Thanks,<br><br>Olivier.<br>