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

davidl davidl at 126.com
Sun Mar 22 22:07:38 PDT 2009


在 Mon, 23 Mar 2009 11:37:56 +0800,Jarrett Billingsley  
<jarrett.billingsley at gmail.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

I think if the runtime typeinfo is modularized to a seperated dll, the  
problem should go away. Just on one think that's a must at the moment.



More information about the Digitalmars-d mailing list