Sorry if I&#39;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 &quot;Module1&quot; module (cannot declare Public functions in the ThisWorkbook module):<br><br><div style="margin-left: 40px;">Public Declare Function adder Lib &quot;
adder.dll&quot; Alias &quot;adder@8&quot; (ByVal x As Long, ByVal y As Long) As Long<br>Public Declare Function adder_Begin Lib &quot;adder.dll&quot; () As Boolean<br>Public Declare Sub adder_End Lib &quot;adder.dll&quot; ()
<br></div><br>Private functions the the &quot;ThisWorkbook&quot; 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 &lt;windows.h&gt;<br>#include &lt;Rts.h&gt;<br><br>#define __ADDER_DLL_EXPORT<br>#define ADDER_API _declspec(dllexport)
<br><br>extern void __stginit_Adder(void);<br><br>static char* args[] = { &quot;ghcDll&quot;, NULL };<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* N.B. argv arrays must end with NULL */<br><br>BOOL STDCALL DllMain( HANDLE hModule, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DWORD&nbsp; ul_reason_for_call, 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LPVOID lpReserved<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ){<br>&nbsp; return TRUE;<br>}<br><br>ADDER_API BOOL adder_Begin(){<br>&nbsp; startupHaskell(1, args, __stginit_Adder);<br>&nbsp; return HS_BOOL_TRUE;<br>}<br><br>ADDER_API void adder_End(){
<br>&nbsp; shutdownHaskell();<br>}<br></div><br>If somebody wants the code and Excel file, just ask, I&#39;ll be happy to provide it.<br><br>Thanks,<br><br>Olivier.<br>