Problem exporting Haskell to C via a DLL in GHC 6.6

Brian Hulley brianh at metamilk.com
Tue Feb 6 04:31:19 EST 2007


SevenThunders wrote:
> Before I post this as a bug, I thought I'd check to make sure I'm not
> doing something wrong.
> BOOL
> STDCALL
> DllMain
>   ( HANDLE hModule
>   , DWORD reason
>   , void* reserved
>   )
> {
>  if (reason == DLL_PROCESS_ATTACH) {
>      /* By now, the RTS DLL should have been hoisted in, but we need
> to start it up. */
>      startupHaskell(1, args, __stginit_Bad);
>      return TRUE;
>  }
>
>  if (reason == DLL_PROCESS_DETACH) {
>        shutdownHaskell();
>        return TRUE;
>  }
>
>  return TRUE;
> }

The above *may* be the problem: it is unsafe to do anything in DllMain that 
may involve loading a DLL, (which therefore includes a lot of the standard 
platform sdk functions, some of which Haskell may need to use to 
start/sthurdown) because the order in which DllMain is called when Windows 
loads/unloads DLLs is undefined - see platform sdk docs for more info.

Instead of trying to start/shutdown Haskell from DllMain, I'd export a 
Begin() and End() function from the DLL and explicitly call these from your 
application's main().

Hope this helps,
Brian.
-- 
http://www.metamilk.com 



More information about the Glasgow-haskell-users mailing list