2017-07-06 122 views
0

當我嘗試使用ComSourceInterfaces而不是typeof字符串參數時,我無法將程序集註冊爲COM對象。我正在實現多個接口,因爲這是SDK所要求的。當我嘗試使用ComSourceInterfaces而不是typeof字符串參數時,我無法將程序集註冊爲COM對象

當我使用

[ComVisible(true), 
ClassInterface(ClassInterfaceType.None), 
ComSourceInterfaces("IAccessControl"), 
Guid("738CFFEF-37DC-4C61-957E-C5A78FE20223")] 
public class EventGeneratorV2 : IAccessControl 

我得到的錯誤

錯誤MSB3217:無法註冊程序集 「... \事件產生v2.dll」。無法從程序集'加載類型'IAccessControl'事件 Generator v2,Version = 1.1.0.0,Culture = neutral, PublicKeyToken = bffdb712704a75b7'。

但是,如果我改變我的代碼使用

[ComVisible(true), 
ClassInterface(ClassInterfaceType.None), 
ComSourceInterfaces(typeof(IAccessControl)), 
Guid("738CFFEF-37DC-4C61-957E-C5A78FE20223")] 
public class EventGeneratorV2 : IAccessControl 

它正確地做工作。我也嘗試了IAccessControl接口的完全限定名,Lib.Interfaces.IAcccessControl作爲字符串,但仍然失敗。最好的解決方案是使用多個ComSourceInterfaces,但只能使用一次,最多使用4個接口。爲了與其他軟件兼容,我需要實現9個接口。有沒有辦法讓字符串工作?

回答

0

好吧我想通了。字符串實際上是每個接口的「Lib.Interfaces.IAcccessControl,Lib」。其中第一部分是接口的完全限定名稱,lib是接口來自的參考。

然後當我添加其他接口時,我必須在每個接口之間添加\ 0。所以我的最後ComSourceInterfaces是相當長的

ComSourceInterfaces("Lib.Interfaces.IAccessControl, Lib\0Lib.Interfaces.IAccessControl2, Lib\0Lib.Interfaces.ITranslate, Lib\0Lib.Interfaces.ITranslate2, Lib\0Lib.Interfaces.IComConfig, Lib\0Lib.Interfaces.IComConfig2, Lib\0Lib.Interfaces.IInput, Lib\0Lib.Interfaces.IInput2, Lib\0Lib.Interfaces.IAsset, Lib\0Lib.Interfaces.IAsset2, Lib\0Lib.Interfaces.IFakeName, Lib\0Lib.Interfaces.IComManager, Lib\0Lib.Interfaces.IDistributeEvent, Lib") 

之後,DLL編譯並正確註冊。

相關問題