@@ -77,6 +77,39 @@ overriders provided by the shared library are removed from the method.
7777include::{shared}/dynamic_main.cpp[tag=unload]
7878----
7979
80+ ### Windows
81+
82+ If we try this example on Windows, the result is disappointing:
83+
84+ ```
85+ Before loading the shared library.
86+ cow meets wolf -> greet
87+ wolf meets cow -> greet
88+
89+ After loading the shared library.
90+ cow meets wolf -> greet
91+ wolf meets cow -> greet
92+ cow meets tiger -> unknown class struct Tiger
93+ ```
94+
95+ What happens here is that the program and the DLL have their own copies of
96+ "global" variables. When the DLL is loaded, its static constructors run, and
97+ they add overriders to _their_ copy of the method (the `method::fn` static
98+ variable for the given name and signature). They are ignored when the main
99+ program calls `initialize` .
100+
101+ Likewise, `BOOST_OPENMETHOD_CLASSES(Tiger, Carnivore);` in the DLL adds `Tiger`
102+ to the DLL's copy of the registry. For the perspective of the program's
103+ registry, the class does not exist.
104+
105+ In theory, this can be fixed by adding `__declspec(dllimport)` and
106+ `__declspec(dllexport)` attributes where needed. However, this is not practical,
107+ because programs and DLLs can both import and export registries and methods. The
108+ underlying objects are instantiated from templates, which complicates the
109+ matter. Research is being done on this subject. However, as of now, dynamic
110+ loading is supported on Windows only if it does not attempt to share a registry
111+ across modules.
112+
80113### Indirect Vptrs
81114
82115`initialize` rebuilds the v-tables in the registry. This invalidates all the
@@ -87,10 +120,10 @@ their execution.
87120
88121Otherwise, indirect v-table pointers must be used. This is achieved by using a
89122registry that contains the cpp:indirect_vptr[] policy.
90- `<boost/openmethod/default_registry.hpp>` provides an ` indirect_registry` which
91- has the same policies as `default_registry`, plus `indirect_vptr`. We can use it
92- to override the default registry, for example using a compiler command-line
93- switch (`-DBOOST_OPENMETHOD_DEFAULT_REGISTRY=indirect_registry`).
123+ `<boost/openmethod/default_registry.hpp>` provides an cpp: indirect_registry[]
124+ that has the same policies as `default_registry`, plus `indirect_vptr`. We can
125+ use it to override the default registry, for example using a compiler
126+ command-line switch (`-DBOOST_OPENMETHOD_DEFAULT_REGISTRY=indirect_registry`).
94127
95128Here is an example of a program that carries `virtual_ptr`{empty}'s across
96129`initialize` calls:
0 commit comments