www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Strange behavior

reply yvad <yannurov gmail.com> writes:
I have 2 modules.

// IUnknown.d
module IUnknown;
pragma(lib, "ole32.lib");

public import HRESULT;

extern (C) {
        const GUID IID_IUnknown;
}

extern (Windows) {
        interface IUnknown {
                HRESULT QueryInterface(in GUID* riid, out void* ppvObject);
                uint AddRef();
                uint Release();
        }
}

abstract class AbstractUnknown : IUnknown {

        extern (Windows):
        // IUnknown
        HRESULT QueryInterface(GUID* riid, out void* ppvObject);
        uint AddRef() {
             ....
        }
        uint Release() {
             ....
        }
}

// and  IClassFactory.d
module win32.api.com.interfaces.IClassFactory;
pragma(lib, "ole32.lib");

public import IUnknown;

extern (C) {
        const GUID IID_IClassFactory;
}

extern (Windows) {
        interface IClassFactory : IUnknown {
                HRESULT CreateInstance(in IUnknown pUnknown, in GUID* riid, out
void* ppvObject);
                HRESULT LockServer(in bool fLock);
        }
}

abstract class AbstractClassFactory : AbstractUnknown, IClassFactory {

        extern (Windows):
        // IUnknown
        HRESULT QueryInterface(in GUID* riid, out void* ppvObject) {
             ....
        }

        ....
}

And I get an error on line in AbstractClassFactory "HRESULT QueryInterface(in
GUID* riid, out void* ppvObject) {":
Severity and Description    Path    Resource    Location    Creation Time    Id
QueryInterface of type HRESULTWindows (GUID * riidriid, out void* ppvObject
ppvObject) overrides but is not covariant with QueryInterface of type
HRESULT(GUID * riidriid, void* ppvObject ppvObject)   
import/win32/api/com/interfaces    IClassFactory.d    line 28    1206420149328 
  12010

if I comment line in AbstractUnknown with "HRESULT QueryInterface(in GUID*
riid, out void* ppvObject);" it compiles without any error.
Is it should be so or I am doing something wrong?

I have this error on dmd 1.028 and 2.012 on Windows.
Mar 25 2008
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"yvad" <yannurov gmail.com> wrote in message 
news:fsam2t$oo3$1 digitalmars.com...

 And I get an error on line in AbstractClassFactory "HRESULT 
 QueryInterface(in GUID* riid, out void* ppvObject) {":
 Severity and Description    Path    Resource    Location    Creation Time 
 Id
 QueryInterface of type HRESULTWindows (GUID * riidriid, out void* 
 ppvObject ppvObject) overrides but is not covariant with QueryInterface of 
 type HRESULT(GUID * riidriid, void* ppvObject ppvObject) 
 import/win32/api/com/interfaces    IClassFactory.d    line 28 
 1206420149328    12010

 if I comment line in AbstractUnknown with "HRESULT QueryInterface(in GUID* 
 riid, out void* ppvObject);" it compiles without any error.
 Is it should be so or I am doing something wrong?

 I have this error on dmd 1.028 and 2.012 on Windows.
Before you go too far with this, you should know that while D has support for COM, that support is kind of "magical." The interface you should be inheriting has already been defined for you in std.c.windows.com. (There's also some stuff in std.windows.iunknown but I'm not sure what that's for.) In std.c.windows.com there's IUnknown and a class called ComObject which implements it, including QueryInterface, AddRef, and Release. The compiler explicitly depends upon you deriving from this IUnknown and I don't know if it will treat your interfaces as COM interfaces unless you do.
Mar 25 2008
parent John C <johnch_atms hotmail.com> writes:
Jarrett Billingsley Wrote:

 In std.c.windows.com there's IUnknown and a class called ComObject which 
 implements it, including QueryInterface, AddRef, and Release.  The compiler 
 explicitly depends upon you deriving from this IUnknown and I don't know if 
 it will treat your interfaces as COM interfaces unless you do. 
 
Actually, any interface called IUnknown will do - it needn't be the one defined in Phobos.
Mar 25 2008
prev sibling next sibling parent reply John C <johnch_atms hotmail.com> writes:
yvad Wrote:

 QueryInterface of type HRESULTWindows (GUID * riidriid, out void* ppvObject
ppvObject) overrides but is not covariant with QueryInterface of type
HRESULT(GUID * riidriid, void* ppvObject ppvObject) 
I'm surprised that's the error you get. Copying your code (and filling in the blanks) I instead get an error about an undefined symbol. You need to mark QueryInterface in AbstractUnknown as abstract.
Mar 25 2008
parent yvad <yannurov gmail.com> writes:
John C Wrote:

 yvad Wrote:
 
 QueryInterface of type HRESULTWindows (GUID * riidriid, out void* ppvObject
ppvObject) overrides but is not covariant with QueryInterface of type
HRESULT(GUID * riidriid, void* ppvObject ppvObject) 
I'm surprised that's the error you get. Copying your code (and filling in the blanks) I instead get an error about an undefined symbol. You need to mark QueryInterface in AbstractUnknown as abstract.
I tried. Same error
Mar 25 2008
prev sibling parent reply John C <johnch_atms hotmail.com> writes:
yvad Wrote:

 QueryInterface of type HRESULTWindows (GUID * riidriid, out void* ppvObject
ppvObject) overrides but is not covariant with QueryInterface of type
HRESULT(GUID * riidriid, void* ppvObject ppvObject)
Further to my other reply ... The compiler is complaining because the function signatures don't match - one is lacking an "out" attribute. But the code you posted isn't missing the "out". Did you change the code before posting it here?
Mar 25 2008
next sibling parent yvad <yannurov gmail.com> writes:
John C Wrote:

 yvad Wrote:
 
 QueryInterface of type HRESULTWindows (GUID * riidriid, out void* ppvObject
ppvObject) overrides but is not covariant with QueryInterface of type
HRESULT(GUID * riidriid, void* ppvObject ppvObject)
Further to my other reply ... The compiler is complaining because the function signatures don't match - one is lacking an "out" attribute. But the code you posted isn't missing the "out". Did you change the code before posting it here?
No. No chages. I also noticed missing out. This was reason I wrote here
Mar 25 2008
prev sibling parent reply yvad <yannurov gmail.com> writes:
John C Wrote:

 yvad Wrote:
 
 QueryInterface of type HRESULTWindows (GUID * riidriid, out void* ppvObject
ppvObject) overrides but is not covariant with QueryInterface of type
HRESULT(GUID * riidriid, void* ppvObject ppvObject)
Further to my other reply ... The compiler is complaining because the function signatures don't match - one is lacking an "out" attribute. But the code you posted isn't missing the "out". Did you change the code before posting it here?
I attached original files
Mar 25 2008
parent reply John C <johnch_atms hotmail.com> writes:
yvad Wrote:

 John C Wrote:
 
 yvad Wrote:
 
 QueryInterface of type HRESULTWindows (GUID * riidriid, out void* ppvObject
ppvObject) overrides but is not covariant with QueryInterface of type
HRESULT(GUID * riidriid, void* ppvObject ppvObject)
Further to my other reply ... The compiler is complaining because the function signatures don't match - one is lacking an "out" attribute. But the code you posted isn't missing the "out". Did you change the code before posting it here?
I attached original files
Compiles OK for me. Be aware that "delete this" in your ref counting code will not free any memory. You should override AbstractUnknown's new and use malloc, then release the memory with free. Nor will COM objects get garbage collected.
Mar 25 2008
parent yvad <yannurov gmail.com> writes:
John C Wrote:

 yvad Wrote:
 
 John C Wrote:
 
 yvad Wrote:
 
 QueryInterface of type HRESULTWindows (GUID * riidriid, out void* ppvObject
ppvObject) overrides but is not covariant with QueryInterface of type
HRESULT(GUID * riidriid, void* ppvObject ppvObject)
Further to my other reply ... The compiler is complaining because the function signatures don't match - one is lacking an "out" attribute. But the code you posted isn't missing the "out". Did you change the code before posting it here?
I attached original files
Compiles OK for me. Be aware that "delete this" in your ref counting code will not free any memory. You should override AbstractUnknown's new and use malloc, then release the memory with free. Nor will COM objects get garbage collected.
Sorry. The error appears only in Eclipse.Descent compilation. Thanks for "delete this". I will investigate it.
Mar 25 2008