Hey!
I' having problems to call functions from a DLL made with ghc
with a C++ program, using Microsofts Visual C++
To learn how to do it, I tried the example found at
the user's guide (11.3, 11.4), but things aren't working out..
Here is as far as I've done:
I have a haskell module, MyModule.hs:module
MyModule where
foreign export stdcall fac :: Int -> Int fac :: Int -> Int fac n | n <= 0 = 1 | otherwise = n * fac(n-1) I compile it with: ghc -c
MyModule.hs -fffi
The .c file, containing the DLL initialization
is:
#include <windows.h>
#include <Rts.h>
extern void __stginit_MyModule(void);
static char *args[] = {"MyDll", NULL};
BOOL STDCALL DllMain(HANDLE hModule, DWORD reason,
void *reserved){
int i;
if(reason ==
DLL_PROCESS_ATTACH){
printf("\nStarting Haskell");
startupHaskell(1, args, __stginit_MyModule);
printf("Haskell Started!!");
return
TRUE;
}
return TRUE;
}
Which I compile with: ghc -c MyDll.c
I build the DLL with: ghc
--mk-dll -o MyDll.dll MyModule.o MyModule_stub.o MyDll.o
The DLL is build, and following the example, I try
to call it from VB, but the program hangs. I don't know if I'm missing something
in the building process, I can't see what it can be.
Moreover, for calling it from my C++ programs, I
need a library file (generally called .lib in MSVC linker, I think it's
equivalent to the libMyLib.a of gcc) to resolve the function (fac) when
linking. I tried to use
dlltool -b MyDll.dll -l
MyDll.lib
to contruct the .lib file, it's contructed, but
yet, when I use to link my C++ program with the DLL, i got unresolved external
symbol for the function.
Thus, I can't even link the C++ program.
Note that I used the stdcall (for fac)to follow the example; I tried even
with ccall, but without success either.
Can someone see if I'm missing something at
the creation process of the dll? And to create the library file, is it the right
thing to do?
Mauricio
|