cast fails for classes from windows dll

Benjamin Thaut via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 13 00:13:47 PST 2016


On Tuesday, 12 January 2016 at 19:00:26 UTC, Andre wrote:
> Hi,
>
> I am not sure, whether this is a current limitation of the 
> windows dll functionality of D
> or I am doing s.th. which will not work.
>
> I have developed in D a windows DLL which creates class 
> instances by passing the name (using object.factory method).
>
> In another D application I am using this DLL. My issue is, that 
> the cast fails, although
> typeid(bar).name shows the correct name .
>
>
> module main;
>
> // these classes are in a seperate module
> // used for the dll & for this application
> export class Foo {}
> export class Bar : Foo {}
> class Baz : Bar {}
>
> void main()
> {
> 	// this method calls the dll and returns Foo
> 	Foo c = dllCreateClass("main.Baz");
> 	
> 	// no failure
> 	assert( typeid(c).name == "main.Baz");
> 	
> 	// ----> fails
> 	if (auto myBar = cast(Bar) c){}
> }
>
> Kind regards
> André

Thats a limitation of the current dll functionality. The type 
info of the class gets duplciated into both your executable and 
the dll and thus the cast fails. Until D properly supports Dlls 
on windows this is going to stay this way. Currently only a C 
like interface across dll boundaries is possible.


More information about the Digitalmars-d-learn mailing list