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:
- Take a
VB6
class with public methods taking or returning some control (for exampleCommonDialog
) reference - Compile this class into an ActiveX dll
- 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
in a Visual Basic 6 ActiveX dll
's class file makes the compilation (* *) fail with the following error:
"Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as fields of public user defined types"
Hence, the question is:
- Is it really impossible to have something like above compile and run properly?
- [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)
(*) -- not an ActiveX exe
, just an "ordinary" one
(* *) provided that appropriate .ocx
("Microsoft Common Dialog Control 6.0 (SP6)", C:\Windows\system32\ComDlg32.OCX) is referenced
(* * *) the only one that I have found is Passing control Ref to dll
(As for the 1st part of the question)
The Microsoft documentation (Data Types Allowed in Properties and Methods ) states:
Can't help you with 1, but 2 should be possible in DotNet 4.0 with the dynamic keyword.