1

I am running Windows 7 (64 bit).
Using version 2014.2.0.0 of Haskell (64 and 32 bit).

With a 32-bit dll and a 32-bit Haskell program this works just fine.
With a 64-bit dll and a 64-bit Haskell program this does not work. Instead I get an access violation.

First-chance exception at 0x0000000000000000 in TestInterop.exe:
0xC0000005: Access violation executing location 0x0000000000000000.

c++ code (built as 64-bit dll):

BOOL __stdcall DllMain(HINSTANCE, DWORD, void*)
{
    return TRUE;
}

extern "C" __declspec(dllexport)  uint64_t ReverseDigits(uint64_t number)
{
    uint64_t result = 0;
    while (number)
    {
        result *= 10;
        result += number % 10;
        number /= 10;
    }
    return result;
}

The Haksell code

module Main where
import Foreign.C
foreign import ccall unsafe "ReverseDigits" interopReverseDigits :: CULLong -> IO CULLong

main = do
    x <- interopReverseDigits(1234)
    if x == 4321
        then putStrLn "Successfully Called Test"
        else putStrLn "Call to test failed"</code></pre>

Is there some sort of special thunk I need to perform in Haskell for this to work?

mcoill
  • 41
  • 5
  • Hopefully a Haskell expert can provide a specific answer, but note that the 64-bit calling conventions are often less lenient than the 32-bit ones, i.e., a mistake that might be harmless in 32-bit can cause crashes in 64-bit. – Harry Johnston Oct 22 '14 at 01:27
  • Works for me, on 64-bit Windows 7, Haskell Platform 2014.2.0.0 (which is ghc 7.8.3). I don't have 32-bit ghc installed. – ja. Oct 22 '14 at 06:55
  • Thanks @ja. I'll look at the compiler options for my DLL and settings for ghc (as it is the same version you have). – mcoill Oct 22 '14 at 13:26
  • @ja., what compiler are you using for the DLL? – mcoill Oct 22 '14 at 19:17
  • 1
    I couldn't get it to compile in VS (haven't set up a DLL project from scratch in years), so I used the gcc that comes with Git Bash. – ja. Oct 24 '14 at 00:34

0 Answers0