c# - 在VB6中创建对象以与用c#编写的dll(tlb)中的对象一起使用?
问题描述
所以我在 vb6 方面的知识相当有限,但这是必需的,因为它是旧代码。
我在 c# 中创建了一个带有对象(字符串类)的 dll。
在 vb6 中使用它的最佳方法是什么?有没有办法可以将它公开为接口,或者在 vb6 中创建一个对象来匹配?
我已经搜索了 MSDN,但该主题的内容非常有限,而不是一个常见的问题。
通常我通过接口公开所有内容,但例如:
class myClass (string x, string y, string z);
不起作用(接口不能包含字段)。
我也试过
myClass(string x, string y, string z);
我得到一个错误方法必须有一个返回类型。
最后我试过了
myClass iClass(string x, string y, string z);
它返回一个不实现接口成员。
我的课
public string x {get;set;}
public string y {get;set;}
public string z {get;set;}
我无法通过搜索找到任何措辞准确的问题(也许我的措辞在标题中是关闭的,因为我的 vb6 知识又是最低限度的)。
所有引用的代码都来自 c# dll。
解决方案
您可以为您的类提供一个 COM 可调用的包装器,VB6 可以与之互操作。
这是您的类,使用可从 VB6 调用的 COM 可调用包装器进行包装:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace CCW
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class myClass
{
public string x { get; set; }
public string y { get; set; }
public string z { get; set; }
}
}
推荐阅读
- flutter - 我想使用颤振导航我在网格视图中的卡片。我的卡片包含图像而不是图标
- python - Google Drive API 使用 Python 下载文件
- python - 如何在 Flask 中获取请求的参数?
- python-3.x - Tensorflow2 数据流水线如何优化?
- ruby - 在 macOS 上更新 RVM、Ruby 和 Rails
- docker - 无法使用 docker ps -a 列出已停止的容器
- java - 更新区域设置不会更改低于 Build.VERSION_CODES.N (API 24) 的 Android 版本的区域设置
- android - java.lang.SecurityException:权限拒绝:启动意图
- c# - 带有附件的 Azure 函数 POST 请求
- ruby-on-rails - 连接到 Rails 服务器时 Puma mini SSL 错误