
Greetings I am trying to import some functions from a windows DLL. I am getting strange errors. (This used to work with previous versions of GHC. 6.6 I think.). This is my import statement: foreign import stdcall "ace.h AdsConnect" adsConnect' :: CString -> Ptr CInt -> IO CInt This is the build output. C:\moonar>\bin\make.exe ghc --make -ffi main.hs -ffi adsapi.hs -optc -DWIN32 native.cpp -lace32 -L/hom e/pjdurai/dev/moonar -L/tmp/Advantage -o moonar.exe [1 of 2] Compiling AdsApi ( adsapi.hs, adsapi.o ) [2 of 2] Compiling Main ( main.hs, main.o ) Linking moonar.exe ... adsapi.o(.text+0x124):fake: undefined reference to `AdsConnect@8' adsapi.o(.text+0x260):fake: undefined reference to `AdsDisconnect@4' collect2: ld returned 1 exit status make: *** [main.exe] Error 1 It actually links without errors if I use 'ccall' instead of 'stdcall'. But the executable segfaults when the function is called. I had the same code working with 'stdcall' declaration a while ago. (With GCH 6.6 I think) I am using ghc-6.8.3 on Windows XP SP2. appreciate your time. thanks pj

On Tue, Jul 15, 2008 at 11:51 PM, PJ Durai
I am trying to import some functions from a windows DLL. I am getting strange errors. (This used to work with previous versions of GHC. 6.6 I think.).
You may have to create an import library for the DLL. I had a similar problem and solved it that way. Look at http://www.emmestech.com/moron_guides/moron1.html for advices on how to create such a library. My problem was that the exports in the dll were prefixed with an underscore. I had to remove them from the .def file before creating the import library. Best regards, Olivier.

On 7/16/08, Olivier Boudry
On Tue, Jul 15, 2008 at 11:51 PM, PJ Durai
wrote: I am trying to import some functions from a windows DLL. I am getting strange errors. (This used to work with previous versions of GHC. 6.6 I think.).
You may have to create an import library for the DLL. I had a similar problem and solved it that way.
Look at http://www.emmestech.com/moron_guides/moron1.html for advices on how to create such a library.
My problem was that the exports in the dll were prefixed with an underscore. I had to remove them from the .def file before creating the import library.
I do have the import library. It came with the DLL. It links properly when I use CCALL on the haskell import statements. Doesnt link when I use STDCALL. It looks for function name with something like '@4 or @8' tacked on at the end. Not sure what that is all about.

On Wed, 16 Jul 2008 10:22:46 -0600, you wrote:
I do have the import library. It came with the DLL. It links properly when I use CCALL on the haskell import statements. Doesnt link when I use STDCALL. It looks for function name with something like '@4 or @8' tacked on at the end. Not sure what that is all about.
This is known as name mangling. See the Wikipedia article for more info: http://en.wikipedia.org/wiki/Name_mangling Steve Schafer Fenestra Technologies Corp. http://www.fenestra.com/

On Wed, Jul 16, 2008 at 6:22 PM, PJ Durai
I do have the import library. It came with the DLL. It links properly when I use CCALL on the haskell import statements. Doesnt link when I use STDCALL. It looks for function name with something like '@4 or @8' tacked on at the end. Not sure what that is all about.
Is your import library a ".lib" or a ".a" file? If you have a ".lib" import library ghc will ignore it and link directly with the DLL. I think you can convert a ".lib" to a ".a" using the reimp tool which is part of the mingw utilities.
participants (3)
-
Olivier Boudry
-
PJ Durai
-
Steve Schafer