有没有一种方法可以通过COM互操作从Visual Basic 6 activeX dll中传递出OCX控件引用? [英] Is there a way to pass an OCX control reference out from a Visual Basic 6 activeX dll via COM interop?

查看:205
本文介绍了有没有一种方法可以通过COM互操作从Visual Basic 6 activeX dll中传递出OCX控件引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试从旧的(但仍保持) VB6 来构建 ActiveX dll 时偶然发现了这个问题code> exe项目(*)源,以便通过 COM / NET 互操作执行一些测试。

I stumbled upon this while trying to build an ActiveX dll from an old (but still maintained) VB6 exe project(*) sources in order to perform some testing via COM / NET interop.


(期望的)用例是:

The (desired) use case is:


  1. 采取 VB6 类,带有使用公共方法或返回某些控件的公共方法(例如 CommonDialog )引用

  2. 将此类编译为ActiveX dll

  3. 通过.NET通过COM interop创建此类的实例,并正确调用其方法

  1. Take a VB6 class with public methods taking or returning some control (for example CommonDialog) reference
  2. Compile this class into an ActiveX dll
  3. Create an instance of this class via COM interop from .NET and correctly call its methods

总之,第一个问题是拥有类似

In short, the first problem is that having something like

Public Function bad_dlg() As CommonDialog
   Set bad_dlg = Nothing
End Function

Visual Basic 6 ActiveX dll 的类文件中的

使编译(* *)失败,并出现以下错误:

in a Visual Basic 6 ActiveX dll's class file makes the compilation (* *) fail with the following error:

私有对象模块不能在公共对象模块中用作公共过程的参数或返回类型,公共数据成员或公共用户定义类型的字段


因此,问题是:

Hence, the question is:


  1. 真的不可能有类似上面的代码可以编译并正常运行?

  2. [如果不是],假设我更改了所有内容以返回并接收 VB6 <$ c $的实例c> Object 类型-我如何使用.Net中的此类实例(调用特定方法等)

  1. Is it really impossible to have something like above compile and run properly?
  2. [IF NOT] Suppose, I change everything to return and receive instances of VB6 Object type -- how can I work with such an instance from .Net (call specific methods, etc)

(*)-不是 ActiveX exe ,只是普通 一个

(*) -- not an ActiveX exe, just an "ordinary" one

(* *),前提是适当的 .ocx ( Microsoft Common Dialog Control 6.0(SP6) ,C:\Windows\system32\ComDlg32.OCX)被引用

(* *) provided that appropriate .ocx ("Microsoft Common Dialog Control 6.0 (SP6)", C:\Windows\system32\ComDlg32.OCX) is referenced

(* * *)我发现的唯一一个是 传递控制权f到dll

(* * *) the only one that I have found is Passing control Ref to dll

推荐答案

(至问题的第一部分)

Microsoft文档(属性和方法中允许的数据类型
)指出:

The Microsoft documentation (Data Types Allowed in Properties and Methods ) states:


关于返回私有对象的弊端



以下数据类型是不允许的,并且对它们的引用绝不能返回给客户端应用程序:

On the Evils of Returning Private Objects

The following data types are not allowed, and references to them should never be returned to client applications:


  • Visual Basic(VB)对象库中提供的所有对象,例如控件。使用对象浏览器查看整个列表。

  • All of the objects provided in the Visual Basic (VB) object library — for example, controls. Use the Object Browser to view the entire list.

所有表单。

全部类模块,其Instancing属性设置为Private。

All class modules whose Instancing property is set to Private.

对ActiveX控件的引用。

References to ActiveX controls.

Visual Basic阻止您将非可视私有对象与进程外组件进行传递。尝试这样做会导致错误98,属性或方法调用不能包含对私有对象的引用,无论是作为参数还是作为返回值。 客户端始终会收到此错误。

Visual Basic prevents you from passing non-visual private objects to or from out-of-process components. Attempting to do so causes error 98, "A property or method call cannot include a reference to a private object, either as an argument or as a return value." This error is always received by the client.

...

重要


  • 私有对象之所以是私有的,通常是因为它们不是为在项目外部使用而设计的。将它们传递给客户端可能会降低程序的稳定性,并导致与Visual Basic的未来版本不兼容。如果需要将自己的私有类传递给客户端,请将Instancing属性设置为Private以外的其他值。

  • Private objects are private for a reason, usually because they were not designed to be used outside your project. Passing them to a client may decrease program stability and cause incompatibility with future versions of Visual Basic. If you need to pass a private class of your own to a client, set the Instancing property to a value other than Private.

[详细信息]

这篇关于有没有一种方法可以通过COM互操作从Visual Basic 6 activeX dll中传递出OCX控件引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆