use delegate with IUnknown

Sergey Gromov snake.scaly at gmail.com
Mon Oct 20 05:38:01 PDT 2008


Mon, 20 Oct 2008 06:53:39 -0400,
Long Chang wrote:
> I compile this code got error....
> 
>    1. interface IUnknown{}  
>    2. class klass : IUnknown{   
>    3.     this(){}      
>    4.     void add(void delegate() dg){}  
>    5. }  
>    6. void main(){  
>    7.     auto t  = new klass;      
>    8.     t.add(delegate void(){});     
>    9. }  
> 
> t2.d(8): function t2.klass.add (void delegate()) does not match parameter types (void delegate())
> t2.d(8): Error: cannot implicitly convert expression (__dgliteral1) of type void delegate() to void delegate() 
> 
> Is this a bug?

IUnknown is a built-in, deeply hacked interface which allows to write 
proper COM objects in pure D.  You must import it from std.c.windows.com 
module.  Obviously it applies some restrictions on methods which can be 
defined there.  Your snipped starts to compile if you replace line 4 with

    extern (Windows) void foo() {}
    t.add(&foo);



More information about the Digitalmars-d mailing list