Article View: comp.windows.ms.programmer
Article #2820Help! Calling Fopen() In Dll
From: Christian Kaiser
Date: Sun, 19 May 1991 11:11
Date: Sun, 19 May 1991 11:11
35 lines
1779 bytes
1779 bytes
> First some info: I am using MS-C 6.0a and MS-C 3.0a.
No: I assume you use MS-Win 3.0a. MSC 3.0 would be too old...
> I am calling a function from a .exe that is in a DLL. This
> function does an fopen() and then returns a FILE *.
OOOOOOOOOps. As far as I see, you made a lot of questionable things...
First of all, the FILE * in the my_fopen() is on the stack, so it will be
overwritten when you use the stack next time (calling fprintf), and that will
cause BIG trouble. So make the FILE * a static variable.
Second, you should declare all pointer parameters in combination with DLLs as
FAR. So it should be
FILE FAR *my_fopen(LPSTR psFileName, LPSTR psMode)
that'll avoid the rest of your problems...
> Am I doing something wrong or is impossible to call fopen() from within
> a DLL and return the FILE * to the exe?
Of course you can. Just remember:
- declare pointers as far (remember 'CS != SS') and
- variables as static if they are used outside the function where they are
declared (the FILE * in this case)
Ok?
Bye!
Christian
Technical Details
Message-ID:
<1502352682@f7220.n241.z2.fidonet.org>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!uunet!math.fu-berlin.de!unido!rwthinf!slcdec!hippo!f1.n6000.z2.fidonet.org!f7220.n241.z2.fidonet.org!Christian_KaiserReferences:
<6358@p1.f6.n242.z2.fidonet.org>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!uunet!math.fu-berlin.de!unido!rwthinf!slcdec!hippo!f1.n6000.z2.fidonet.org!f7220.n241.z2.fidonet.org!Christian_Kaiser From: Christian_Kaiser@f7220.n241.z2.fidonet.org (Christian Kaiser) Newsgroups: comp.windows.ms.programmer Subject: Help! Calling Fopen() In Dll Message-ID: <1502352682@f7220.n241.z2.fidonet.org> Date: 19 May 91 11:11:00 GMT References: <6358@p1.f6.n242.z2.fidonet.org> Reply-To: Christian_Kaiser%f7220.n241.z2@hippo.dfv.rwth-aachen.de (Christian Kaiser) Organization: Maybe I should start labeling my software? Lines: 36 Comment-To: Dxg@f1.n6000.z2.fidonet.org (Dxg)