我可以在 VB6 中使用相同的库作为组件和参考吗?

发布于 2025-01-05 16:38:41 字数 131 浏览 0 评论 0原文

我想使用 Winsock Comm 控件。某些表单将其用作表单(组件)上的控件,但我也有一些具有引用并创建新的 MSComm 对象的类。

VB6 似乎失败了。您可以将其添加为组件或参考。有没有办法在同一个项目中同时完成这两项工作?

I would like to use the Winsock Comm control. Some forms have used it as a control on the form (component) but I also have some classes which have references and created a new MSComm object.

This seems to fail with VB6. You can either add it as a component or reference. Is there any way to do both in the same project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

初与友歌 2025-01-12 16:38:41

您可以使用 mktyplib.exe 编译自定义“直接控件”类型库,如下

[
  uuid(<<GUID_HERE>>),
  version(1.0),
  helpstring("Direct Controls Typelib 1.0")
]
library DirectControls10
{
    importlib("C:\\WINDOWS\\system32\\mscomm32.ocx");

    typedef [public] MSCommlib.MSComm DirectMSComm;
}

所示 在项目中引用 DirectControls10 后,您可以使用 DirectMSComm coclass沿着 MSCommlib.MSComm 用户控件,如下所示

Private WithEvents m_oComm      As DirectMSComm

Private Sub Form_Load()
    Set m_oComm = New DirectMSComm
    Set m_oComm = CreateObject("MSCommlib.MSComm")
    Set m_oComm = MSComm1.Object
End Sub

Private Sub m_oComm_OnComm()
    Debug.Print "m_oComm_OnComm"; Timer
End Sub

...在上面的示例中,MSComm1Form1 上的“通信控件”。

不必必须将此自定义.tlb 文件分发给您的客户。仅在您的开发机器上使用它。

You can use mktyplib.exe to compile a custom "direct controls" typelib like this

[
  uuid(<<GUID_HERE>>),
  version(1.0),
  helpstring("Direct Controls Typelib 1.0")
]
library DirectControls10
{
    importlib("C:\\WINDOWS\\system32\\mscomm32.ocx");

    typedef [public] MSCommlib.MSComm DirectMSComm;
}

Once you reference DirectControls10 in your project you can use DirectMSComm coclass along MSCommlib.MSComm usercontrol like this

Private WithEvents m_oComm      As DirectMSComm

Private Sub Form_Load()
    Set m_oComm = New DirectMSComm
    Set m_oComm = CreateObject("MSCommlib.MSComm")
    Set m_oComm = MSComm1.Object
End Sub

Private Sub m_oComm_OnComm()
    Debug.Print "m_oComm_OnComm"; Timer
End Sub

... where in the sample above MSComm1 is a "comm control" on Form1.

You don't have to distribute this custom .tlb file to you clients. Use it on your dev machines only.

蓦然回首 2025-01-12 16:38:41

我相信组件引用是一种特殊的引用。因此,一旦引用了某个组件,就可以将其作为引用的库进行访问。

I believe a component reference is a special kind of reference. So once you have referenced a component, you can access it as a referenced library.

何止钟意 2025-01-12 16:38:41

您是在谈论 Winsock 还是 MSComm?

如果是后者,请从表单中删除该组件,然后将其作为工具箱中的组件删除。

将其添加为引用,并在以前有组件手动声明实例的表单中;

private withevents comm as MSComm

_load 中创建它们

set comm = new MSComm

,只要变量名称相同,所有事件都应该连接起来。

如果它是 Winsock 组件,那么最简单的方法是使用 OCX 组件和 OCX 组件。根据需要将引用从表单传递到类,因为您无法可靠地提前绑定 Winsock 组件; set wsck1 = new Winsock 将编译并创建运行良好,但在任何没有安装 VB6 的机器上,它都会失败,因为每次以这种方式创建一个组件时,winsock 组件都会进行许可证验证。

我 90% 确信 mscomm 不是这种情况,但无论如何最好进行测试。

Are you talking about Winsock or MSComm?

If its the latter, remove the component from the forms then remove it as a component in the tool box.

Add it as a reference and in the forms where previously there were components declare the instance manually;

private withevents comm as MSComm

creating them in _load

set comm = new MSComm

and all your events should be wired up so long as the variable name is the same.

If its a Winsock component then the simplest way is to use the OCX component & pass a reference from the form to the class as necessary, as you cannot reliably early bind a winsock component; set wsck1 = new winsock will compile & run fine but on any machine without VB6 installed it will fail as the winsock component does a license validation everytime one is created in that fashion.

I am 90% sure this isnt the case for mscomm but best to test anyway.

-柠檬树下少年和吉他 2025-01-12 16:38:41

无论如何,UserControl 是类的一种特殊形式,因此要包装控件,您需要创建一个 UserControl。您可以通过明确命名的 InvisibleAtRuntime 属性轻松地使非 UI UserControl 在运行时不可见。

A UserControl is a specialized form of Class anyway, so to wrap a control you create a UserControl. You can easily make a non-UI UserControl invisible at runtime via the clearly named InvisibleAtRuntime property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文