instance of sub class created in a dll has wired behaviour when cast

liyu yunwind at msn.com
Sun Mar 22 21:25:05 PDT 2009


"Jarrett Billingsley" <jarrett.billingsley at gmail.com> wrote in message 
news:mailman.986.1237779483.22690.digitalmars-d at puremagic.com...
> 2009/3/22 liyu <yunwind at msn.com>:
>> I am not sure it's a bug of tango or dmd, so i post it here. The example
>> code as below
>>
>> ...
>>
>> The result is:
>> Library successfully loaded
>> Symbol dllprint found. Address = 0x1000308c
>> mydll.DummyC
>> mydll.DummyC
>> tango.core.Exception.AssertException at test(35): Assertion failure
>>
>> As you see, var a is a instance of DummyC which is a subclass of DummyB, 
>> but
>> the cast is failure.
>
> This is, unfortunately, a limitation imposed by Windows DLLs.  DLLs
> cannot, by their nature, load symbols out of the host application that
> loads them.  As a result, the typeinfo of classes is duplicated, one
> copy in the host and one in each DLL.  Thus you end up with classes
> which _look_ the same, but casting them will inevitably fail.  There
> is no real robust solution while still using DLLs, and the problem
> only exists on Windows.
>
> DDL attempts (and succeeds, quite nicely) in performing manual dynamic
> linking.  http://www.dsource.org/projects/ddl

wow, I never known that before, thanks! 




More information about the Digitalmars-d mailing list