From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Carlos Albar-Diaz" To: gnu-win32@cygnus.com Subject: Re: DLL help needed Date: Sat, 14 Nov 1998 03:05:00 -0000 Message-id: <19981114105740.21077.qmail@findmail.com> References: <3646EB36.35E244A9@uniweb.se> X-SW-Source: 1998-11/msg00618.html I have failed in my attempt to modify Mumit's "dllhelpers" package to create dlls from WINAPI/__stdcall functions. It works all right when the function inputs/outputs are integers, but it fails when I try to use floats or doubles. I have browsed all the relevant archives and I have seen similar problems reported, but no solutions. Any ideas? I will appreciate them very much. BTW, I am using egcs1.1 for mingw32. Thanks, Carlos PS: Thanks Jens for your comments, now I attach all the files for your enjoyment :) This is the (failed) output of the program usedll.c, attached below: ----------------- dll_double_square (3.0) = -1.#IND00 ---> calcs the square of a double (fails with WINAPI convention) dll_int_square (30,40) = 1200 ---> multiplies 2 ints, works OK ------------------ When I get rid of the WINAPI attributes, everything works well. The problem I have is that I have to use WINAPI to call the DLL from MS Excel. All the sources and make commands follow: ------------------- make commands ------------------- gcc -c -DBUILDING_DLL=1 -I. -g -Wall -o cdll.o cdll.c gcc -c -DBUILDING_DLL=1 -I. -g -Wall -o dllinit.o dllinit.c dlltool --export-all --output-def cdll.def cdll.o dllinit.o dllwrap --def cdll.def --driver-name gcc -o cdll.dll \ cdll.o dllinit.o gcc -c -I. -g -Wall -o usedll.o usedll.c dlltool --dllname cdll.dll --def cdll.def \ --output-lib libcdll.a gcc -o usedll.exe -g -Wall usedll.o -L./ -lcdll C:\usr\dll\c> ------------------------ cdll.c ------------------------- #include "cdll.h" DLLIMPORT WINAPI int dll_int_square (int i, int j) { return i * j; } DLLIMPORT WINAPI double dll_double_square (double d) { return d * d; } ------------------------ cdll.h ------------------------- #include "windows.h" //CAD inserted this #ifndef cdll_h_included #define cdll_h_included #if BUILDING_DLL # if __GNUC__ && ! defined(__declspec) # define DLLIMPORT # define DECLSPEC_NOT_SUPPORTED # else /* ! __GNUC__ || __declspec */ # define DLLIMPORT __declspec (dllexport) # endif /* ! __GNUC__ || __declspec */ #else /* Not BUILDING_DLL */ # if __GNUC__ && ! defined(__declspec) # define DLLIMPORT extern # define DECLSPEC_NOT_SUPPORTED # else /* ! __GNUC__ || __declspec) */ # define DLLIMPORT __declspec (dllimport) # endif /* ! __GNUC__ || __declspec) */ #endif /* Not BUILDING_DLL */ DLLIMPORT WINAPI int dll_int_square (int, int) ; DLLIMPORT WINAPI double dll_double_square (double); #ifndef DECLSPEC_NOT_SUPPORTED #else /* DECLSPEC_NOT_SUPPORTED */ #define dll_global_int_var (*_imp__dll_global_int_var) #endif /* DECLSPEC_NOT_SUPPORTED */ #endif /* cdll_h_included */ ------------------------ usedll.c ------------------------- #include #include "cdll.h" int main () { printf ("dll_double_square (3.0) = %f\n", dll_double_square (3.0)); printf ("dll_int_square (30,40) = %d\n", dll_int_square (30,40)); return 0; } ----------------------------- cdll.def (generated automatically, same for the import library and the dll) ----------------------------- ; dlltool --export-all --output-def cdll.def cdll.o dllinit.o EXPORTS dll_int_square@8 @ 1 ; dll_double_square@8 @ 2 ; ----------------------------- dllinit.c ----------------------------- /* dllinit.c -- Portable DLL initialization. Copyright (C) 1998 Free Software Foundation, Inc. Contributed by Mumit Khan (khan@xraylith.wisc.edu). */ #define WIN32_LEAN_AND_MEAN #include #undef WIN32_LEAN_AND_MEAN #include BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved /* Not used. */ ); #ifdef __CYGWIN32__ #include DECLARE_CYGWIN_DLL( DllMain ); /* save hInstance from DllMain */ HINSTANCE __hDllInstance_base; #endif /* __CYGWIN32__ */ BOOL APIENTRY DllMain ( HINSTANCE hInst /* Library instance handle. */ , DWORD reason /* Reason this function is being called. */ , LPVOID reserved /* Not used. */ ) { #ifdef __CYGWIN32__ __hDllInstance_base = hInst; #endif /* __CYGWIN32__ */ switch (reason) { case DLL_PROCESS_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } return TRUE; }  > What exactly is the problem? Do you get any error messages? How does > the names look in the .dll? Have you exported the functions? I'm not > sure the __stdcall does that. I guess you link a .def file with the .dll > to export the functions. Have you looked att the site for mingw32??? > > Jens Yllman > ----- See the original message at http://www.egroups.com/list/gnu-win32/?start=9054 - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request@cygnus.com" with one line of text: "help".