cast fails for classes from windows dll

Andre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 12 11:00:26 PST 2016


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é


More information about the Digitalmars-d-learn mailing list