From: Roger K. W. <ROG...@sa...> - 2003-05-21 14:04:02
|
Virtual wrote: > I have a little problem sharing variables from a DLL to > another...please see this example: > > -------- FILE 1: hello.c -------- > > #include "dllfct.h" > > int main () { > i = 5; > tstfunc(); > i = 2; > tstfunc2(); > return (0); > } > > --------- FILE 2: dllfct.h ------- > > #ifdef BUILD_DLL > #define EXPORT __declspec(dllexport) > #else > #define EXPORT __declspec(dllimport) > #endif > > EXPORT int i; > EXPORT void tstfunc (void); > > --------- FILE 3: dllfct.c ---------- > > #include <stdio.h> > #include "dllfct.h" > > EXPORT int i=0; > > EXPORT void tstfunc (void) { > printf ("Hello%d\n", i); > } > ---------- FILE 4: dllfct2.h ----------- > EXPORT void tstfunc2 (void); > ---------- FILE 5: dllfct2.c ----------- > > #include <stdio.h> > #include "dllfct.h" > #include "dllfct2.h" > > EXPORT void tstfunc2 (void) { > printf("VAL IS=%d", i); > } > > ---------- COMPILED WITH: -------------- > > gcc -DBUILD_DLL -shared -o tst.dll dllfct.c > -Wl,--output-def,tstdll.def,--out-implib,libtstdll.a > > gcc -DBUILD_DLL -shared -o tst2.dll dllfct2.c > -Wl,--output-def,tst2dll.def,--out-implib,libtstdll2.a > > gcc -o hello.exe hello.o -L./ -ltstdll -ltstdll2 > > ----------- BUT ON VIDEO: ---------------- > > Hello5 > VAL IS=0 > > -------------------------------------------- > > how can I view the changes to i, maded by hello.c, from tstfunc2 into > tst2.dll ???? > > Please, it's very important. > > > P.S: 'scuse for my bad english!!! you need two BUILD_DLL macros. This because when you are building dllfct2.dll you are in fact using dllfct.dll. Define DLLFCT_BUILD_DLL & DLLFCT2_BUILD_DLL & define them as appropriate hope this helps -- Roger Wells, P.E. SAIC 221 Third St Newport, RI 02840 401-847-4210 (voice) 401-849-1585 (fax) ro...@mt... |