On Monday, 24 November 2014 at 20:56:29 UTC, Rainer Schuetze
wrote:
On 24.11.2014 19:20, MrSmith wrote:
I've got little test here
https://gist.github.com/MrSmith33/8750dd43c0843d45ccf8#file-sharedmodule2-d-L17-L29.
I have one application and two dlls. Application loads both
dlls, calls
their factory functions and then passes each IModule instance
that it
got from factories to those modules.
Modules then try to cast those IModule refs back to their real
interfaces (ISharedModule1) but i am getting null there.
The different DLLs have different copies of the RTTI for the
classes (you could not link them separately otherwise). Looking
for base classes or derived classes only compares RTTI
pointers, so it doesn't find the target class of a cast in the
hierarchy inside another DLL.
A have found a workaround for this by returning a void*
pointer to real
interface and it back when needed.
Another workaround for a limited number of classes would be to
add member functions 'ISharedModule1 toSharedModule1() { return
null; }' in IModule and override these 'ISharedModule1
toSharedModule1() { return this; }' in the appropriate class.
Another, and more major issue is, that when exception is thrown
application fail immediately.
Is it broken on windows, or it is me doing it wrong?
I haven't tried in a while but I think it should work on Win32,
but probably does not on Win64.
I thought it will work at least for interfaces.
Any way, this is workaroundable, but exceptions must be there at
least.