2015-02-04 73 views
1

當我要求Visual Studio爲我的COM組件生成運行時可調用包裝器時,它會選擇一個奇怪的類型來包裝某個接口屬性。爲什麼生成的包裝屬性類型選擇這個接口?

這是組分A的彙總類型庫:

// Generated .IDL file (by the OLE/COM Object Viewer) 
// 
// typelib filename: prodist.sts.dll 

[ 
    uuid(DD00B52D-D8F9-4D5C-ADBD-4E05A68A48CB), 
    version(5.4), 
    custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 134218331), 
    custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 1423075247), 
    custom(DE77BA65-517C-11D1-A2DA-0000F8773CE9, "Created by MIDL version 8.00.0603 at Wed Feb 04 16:40:46 2015 
"), 
    custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "prodist.sts") 

] 
library prodist_sts 
{ 
    // TLib :  // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046} 
    importlib("stdole2.tlb"); 
    // TLib : : {F11596CA-03EE-4756-B502-0327800ED8B4} 
    importlib("prodist.logging.dll"); 

    // Forward declare all types defined in this typelib 
    interface ISts; 
    interface IStsSession; 
    interface IStream; 
    interface ISequentialStream; 

    [ 
     uuid(EE263AAA-67D4-48DD-9DF5-69ED8CF0D0C9) 
    ] 
    coclass Sts { 
     [default] interface ISts; 
    }; 

    [ 
     odl, 
     uuid(8D841E5C-F25B-4C12-B03A-70A899B3A32E), 
     dual, 
     nonextensible, 
     oleautomation 
    ] 
    interface ISts : IDispatch { 
     [id(0x000003e9), propget] 
     HRESULT Logging([out, retval] IProdistLoggingHierarchy** value); 
     [id(0x000003e9), propput] 
     HRESULT Logging(IProdistLoggingHierarchy* value); 
     [id(0x000003e8)] 
     HRESULT CreateSession([out, retval] IStsSession** result); 
    }; 

    // ... 
} 

這是組分B類型庫:

// Generated .IDL file (by the OLE/COM Object Viewer) 
// 
// typelib filename: prodist.sts.rsfn.dll 

[ 
    uuid(C8FBF2B0-9218-4B0D-9509-C394D65F0566), 
    version(5.4), 
    custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 134218331), 
    custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 1423076189), 
    custom(DE77BA65-517C-11D1-A2DA-0000F8773CE9, "Created by MIDL version 8.00.0603 at Wed Feb 04 16:56:28 2015 
"), 
    custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "prodist.sts.rsfn") 

] 
library prodist_sts_rsfn 
{ 
    // TLib :  // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046} 
    importlib("stdole2.tlb"); 
    // TLib : : {DD00B52D-D8F9-4D5C-ADBD-4E05A68A48CB} 
    importlib("prodist.sts.dll"); 
    // TLib : : {F11596CA-03EE-4756-B502-0327800ED8B4} 
    importlib("prodist.logging.dll"); 

    // Forward declare all types defined in this typelib 
    interface IApiMensageria2; 
    interface IApiMensageria; 
    interface IApiMensageriaContext; 
    interface IStsRsfn; 
    interface IStsRsfnContext; 
    interface IStsRsfnSession; 

    [ 
     uuid(914E8C54-E0F0-4322-8803-8E9EEEE03A01) 
    ] 
    coclass StsRsfn { 
     [default] interface IStsRsfn; 
    }; 

    [ 
     odl, 
     uuid(13385FC6-2618-4830-A3A9-703398AA5A0B), 
     dual, 
     nonextensible, 
     oleautomation 
    ] 
    interface IStsRsfn : IDispatch { 
     [id(0x000003e9), propget] 
     HRESULT Logging([out, retval] IProdistLoggingHierarchy** value); 
     [id(0x000003e9), propput] 
     HRESULT Logging(IProdistLoggingHierarchy* value); 
     [id(0x000003e8), propget] 
     HRESULT Sts([out, retval] ISts** value); 
     [id(0x000003e8), propput] 
     HRESULT Sts(ISts* value); 
     [id(0x000003f1)] 
     HRESULT CreateContext([out, retval] IStsRsfnContext** result); 
     [id(0x000003f2)] 
     HRESULT CreateSession([out, retval] IStsRsfnSession** result); 
    }; 

    // ... 
} 

這是由Visual Studio對於組分A中產生的運行時調用包裝:

[ClassInterface(0)] 
[Guid("EE263AAA-67D4-48DD-9DF5-69ED8CF0D0C9")] 
[TypeLibType(2)] 
public class StsClass : ISts, Sts 
{ 
    public StsClass(); 

    [DispId(1001)] 
    public virtual IProdistLoggingHierarchy Logging { get; set; } 

    [DispId(1000)] 
    public virtual IStsSession CreateSession(); 
} 

[CoClass(typeof(StsClass))] 
[Guid("8D841E5C-F25B-4C12-B03A-70A899B3A32E")] 
public interface Sts : ISts 
{ 
} 

[Guid("8D841E5C-F25B-4C12-B03A-70A899B3A32E")] 
[TypeLibType(4288)] 
public interface ISts 
{ 
    [DispId(1001)] 
    IProdistLoggingHierarchy Logging { get; set; } 

    [DispId(1000)] 
    IStsSession CreateSession(); 
} 

這是運行時可調用的包裝器,由Visual Studio中的成分B:

[ClassInterface(0)] 
[Guid("914E8C54-E0F0-4322-8803-8E9EEEE03A01")] 
[TypeLibType(2)] 
public class StsRsfnClass : IStsRsfn, StsRsfn 
{ 
    public StsRsfnClass(); 

    [DispId(1001)] 
    public virtual IProdistLoggingHierarchy Logging { get; set; } 
    [DispId(1000)] 
    public virtual Sts Sts { get; set; } 

    [DispId(1009)] 
    public virtual IStsRsfnContext CreateContext(); 
    [DispId(1010)] 
    public virtual IStsRsfnSession CreateSession(); 
} 

[CoClass(typeof(StsRsfnClass))] 
[Guid("13385FC6-2618-4830-A3A9-703398AA5A0B")] 
public interface StsRsfn : IStsRsfn 
{ 
} 

[Guid("13385FC6-2618-4830-A3A9-703398AA5A0B")] 
[TypeLibType(4288)] 
public interface IStsRsfn 
{ 
    [DispId(1001)] 
    IProdistLoggingHierarchy Logging { get; set; } 
    [DispId(1000)] 
    Sts Sts { get; set; } 

    [DispId(1009)] 
    IStsRsfnContext CreateContext(); 
    [DispId(1010)] 
    IStsRsfnSession CreateSession(); 
} 

爲什麼Visual Studio中選擇STS的接口,而不是派接口來包裝IStsRsfn.Sts財產?

回答

0

因爲接口IStsSts coclass的默認接口,沒有其他coclass實現它。

在這種情況下,我猜測導入器會選擇它曾經看到的界面作爲某個coclass的默認界面,而不是其他的界面。