[英]C# and com for vb6
我有 C# 和 COM 的問題。
[Guid("f7d936ba-d816-48d2-9bfc-c18be6873b4d")]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class Process : IProcess
{
public Process()
{
}
public int UpdateBalance(string accountNumber, string adminEventDescription, decimal curAmount)
{
return 10;
}
}
[ComVisible(true)]
[Guid("5c640a0f-0dce-47d4-87df-07cee3b9a1f9")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IProcess
{
int UpdateBalance(string accountNumber, string adminEventDescription, decimal curAmount);
}
和VB代碼
Private Sub Command1_Click()
Dim test As Object
Set test = New Forwardslash_PlayerTrackingSystem_Api.Process
End Sub
我得到以下信息,
ActiveX 組件無法創建對象?
關於如何解決問題的任何想法?
您是否勾選了項目屬性中的“注冊 COM 互操作”框?
您是否也在 C# 源代碼中定義了ProgID Forwardslash_PlayerTrackingSystem_Api.Process
? 您的示例代碼似乎不包含它。 (或者您是否正在使用現有的類型庫並通過 GUID 在 VB 中以某種方式創建對象?)
並且在運行 VB 代碼的機器上的注冊表中是否正確注冊了 C# 組件? 當您使用regasm.exe工具自行構建和/或注冊 VisualStudio 時,請參閱Paolo的答案,了解如何讓 VisualStudio 為您執行此操作。 此工具等效於用於“真實”COM 對象的regsrv32.exe ,但隨后會在注冊表中注冊適當構建的 .NET 程序集以供 COM 使用。
您的 [InterfaceType] 屬性錯誤。 VB6 需要 IDispatch 接口,它不能處理 IUnknown 接口。 它最喜歡 ComInterfaceType.InterfaceIsDual,它生成完整的類型庫,在 VB6 編輯器中啟用 IntelliSense,並且比后期綁定的 IDispatch 快大約 1000 倍。
如果程序集未在 GAC 中注冊,則必須使用regasm
的/codebase
開關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.