From: SMTP%"Steve_Weinrich@keyvision.com" 24-OCT-1997 16:24:49.31 To: "'john.muller@peri.com'" , ntdev@atria.com CC: Subj: RE: dll problem Return-Path: owner-ntdev@atria.com Received: by arisia.gce.com (UCX V4.1-12C, OpenVMS V7.1 VAX); Fri, 24 Oct 1997 16:22:17 -0400 Received: from gw.atria.com (gw.atria.com [192.88.237.2]) by mercury.mv.net (8.8.7/mem-951016) with SMTP id UAA08343 for ; Thu, 23 Oct 1997 20:45:48 -0400 (EDT) Received: by gw.atria.com id Thu, 23 Oct 1997 15:00:24 -0400 Received: from cip-server.cipartners.com by gw.atria.com id Thu, 23 Oct 1997 15:00:19 -0400 Received: by cip.cipartners.com with Internet Mail Service (5.0.1458.49) id ; Thu, 23 Oct 1997 14:59:35 -0400 Message-ID: From: Steve Weinrich To: "'john.muller@peri.com'" , ntdev@atria.com Subject: RE: dll problem Date: Thu, 23 Oct 1997 14:59:34 -0400 X-Priority: 3 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1458.49) Content-Type: text/plain; charset="iso-8859-1" Sender: owner-ntdev@atria.com Precedence: bulk Here's what's happening: When you run you LINKer against your "dynamiclib"'s .objs and, on the link line, specify the name of your static library, the linker sucks in the routines it needs from the LIB (like do_static_lib_init()) and incorporates them into your new DLL ("dynamiclib" in your case). The product of the link is a DLL and a LIB. The lib is a little file which is called an import lib. It contains no code, only information about the routines your DLL is exporting; for example: do_dynamic_lib_init( ). Without even considering the EXE, you already have a one (1) copy of the routine do_static_lib_init(). When you run your LINKer against "myapp"'s .obj's and, on the link line, specify the name of your static library, the linker sucks in the routines it needs from the static LIB (like do_static_lib_init()) and incorporates the actual code into your new EXE ("myapp" in your case), just like it would for any OBJ's that were listed on the LINKer line. You have also included, on the link line, the import library for your DLL (unless of course you use LoadLibrary()) so that your EXE can call the DLL's do_dynamic_lib_init(). No problem here, I mention it only so that you'll be sure to recognize that the actual code for do_dynamic_lib_init() is not linked into the EXE, as is the code from your static lib. Instead, the code still resides in your DLL. Now, you have two copies (identical sure, but two individual copies none the less) of your "do_static_lib_init()" routine. One in your DLL and one in your EXE. When you run your EXE, it calls it's own copy of "do_static_lib_init() and then calls the code inside the DLL for "do_dynamic_lib_init()", which in turn calls the its own copy (the DLL's copy) of "do_static_lib_init()". How do you fix this? One of two things: 1) Implement the routines inside the static lib as a DLL. Perhaps you can simply roll the routines from the static library into the DLL. -or- 2) Export the do_static_lib_init() call FROM the EXE, and do not include the static library on the DLL's link line. Have the DLL call into your EXE to initialize the static library. Hope this helps. -Steve Weinrich weinrich@keyvision.com > -----Original Message----- > From: john.muller@peri.com [SMTP:john.muller@peri.com] > Sent: Thursday, October 23, 1997 8:16 AM > To: ntdev@atria.com > Subject: dll problem > > > Hello, > > I have the following scenerio: > > Static Library (staticlib.lib) contains function do_static_lib_init() > and > a static variable initialized. > > Dynamic Library (dynamiclib.dll) contains function > do_dynamic_lib_init(). This > function makes a call to do_static_lib_init(). > > Application (myapp) which calls do_static_lib_init() and > do_dynamic_lbi_init(). > > It appears that both the application (myapp) and dynamic library has > its own > copy of the static library (staticlib.lib). > > Does anybody know what is going on here? > > Does anybody know how to get around this? > > Below is output and sample code which illustrates this all: > > ENTER main() > ENTER do_static_lib_init() > Initialized > EXIT do_static_lib_init() > ENTER do_dynamic_lib_init() > ENTER do_static_lib_init() > Initialized > EXIT do_static_lib_init() > EXIT do_dynamic_lib_init() > EXIT main() > > ***** staticlib.lib source ***** > > #include > #include > > #include "../defs.h" > > static int initialized = 0; > > extern void > do_static_lib_init( void ) { > MSG("ENTER do_static_lib_init()"); > > if ( !initialized ) { > initialized = 1; > > MSG("Initialized"); > } > > MSG("EXIT do_static_lib_init()"); > } > > ***** dynamic.lib source ***** > > #include > #include > > #define __DLL_SOURCE > #include "../defs.h" > #undef __DLL_SOURCE > > extern void > do_dynamic_lib_init( void ) { > > MSG("ENTER do_dynamic_lib_init()"); > > do_static_lib_init( ); > > MSG("EXIT do_dynamic_lib_init()"); > } > > > ***** myapp source ***** > > #include > #include > > #include "../defs.h" > > extern int > main( int argc, char **argv ) { > MSG("ENTER main()"); > > do_static_lib_init(); > do_dynamic_lib_init(); > > MSG("EXIT main()"); > > return 1; > } > > > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > [ To unsubscribe, send email to ntdev-request@atria.com with body > UNSUBSCRIBE (the subject is ignored). ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ To unsubscribe, send email to ntdev-request@atria.com with body UNSUBSCRIBE (the subject is ignored). ]