From: <dan...@ya...> - 2000-10-25 10:45:10
|
I think the problem is that none of the C runtime prototypes in mingw headers are explicitly marked as __cdecl. -mrtd declares everything __stdcall (but doesn't use __stdcall decoration so no link time error) Sooner or later at runtime there will be a stack overflow You have two options: 1) declare all (or at least the ones you use) the C runtime prototypes as __cdecl, then -mrtd should work 2) don't use -mrtd, but explicitly mark your dllexports/imports as __stdcall eg #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) __stdcall #else /* Not BUILDING_DLL */ # define DLLIMPORT __declspec (dllimport) __stdcall #endif /* Not BUILDING_DLL */# and void DLLIMPORT filetest(char *fname) Danny --- Erik Terpstra <er...@so...> wrote: > When I build hunks.dll in the example below, and use its filetest > function in usedll.exe, it crashes with a stack error when reading > large > files (postscript files several MB's in size). > However, when I remove the -mrtd options from the build instructions, > it > works fine. But then I can't use the DLL in Visual Basic, because VB > only supports the stdcall mechanism (which is activated using the > -mrtd > option). > > I'm aware that this particular DLL doesn't do anything useful yet, > but > (when supporting stdcalls) it cannot read large files in the first > place. > > Ideas anyone? > > TIA, > > Erik. > > > gcc -c -DBUILDING_DLL=1 -mrtd -I. -g -Wall --pedantic -o hunks.o > hunks.c > > gcc -c -DBUILDING_DLL=1 -mrtd -I. -g -Wall -o dllinit.o dllinit.c > dllwrap --export-all --output-def hunks.def --implib libhunks.a -o > hunks.dll hunks.o dllinit.o > gcc -c -I. -g -Wall -o usedll.o usedll.c > dllwrap --export-all --output-def hunks.def --implib libhunks.a -o > hunks.dll hunks.o dllinit.o > gcc -o usedll.exe -g -Wall usedll.o -L./ -lhunks > > > > /*-- usedll.c ------------------------------------------*/ > #include <stdio.h> > #include "hunks.h" > > int main(int argc,char *argv[]){ > printf("BEGIN\n"); > filetest("verybigfile.ps"); > return 0; > } > > /*-- hunks.c ------------------------------------------*/ > #include <stdio.h> > #include "hunks.h" > > DLLIMPORT void filetest(char *fname){ > char ch; > FILE *f; > > if((f=fopen(fname,"rb"))){ > while(!feof(f)){ > ch=getc(f); > } > fclose(f); > } > } > > /*-- dllinit.c ------------------------------------------*/ > #define WIN32_LEAN_AND_MEAN > #include <windows.h> > #undef WIN32_LEAN_AND_MEAN > #include <stdio.h> > > BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, > LPVOID reserved /* Not used. */ ); > > BOOL APIENTRY > DllMain ( > HINSTANCE hInst /* Library instance handle. */ , > DWORD reason /* Reason this function is being called. */ , > LPVOID reserved /* Not used. */ ) > { > > switch (reason) > { > case DLL_PROCESS_ATTACH: > break; > > case DLL_PROCESS_DETACH: > break; > > case DLL_THREAD_ATTACH: > break; > > case DLL_THREAD_DETACH: > break; > } > return TRUE; > } > > /*-- hunks.h ------------------------------------------*/ > #ifndef hunks_h_included > #define hunks_h_included > #if BUILDING_DLL > # define DLLIMPORT __declspec (dllexport) > #else /* Not BUILDING_DLL */ > # define DLLIMPORT __declspec (dllimport) > #endif /* Not BUILDING_DLL */ > > DLLIMPORT void filetest(char *fname); > > #endif /* hunks_h_included */ > > > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options at: > http://lists.sourceforge.net/mailman/listinfo/mingw-users _____________________________________________________________________________ http://clubs.yahoo.com.au - Yahoo! Clubs - Join a club or build your own! |