VB6 ActiveX Control. CreateDispatch 'ed in VC++6; passed to VB dll; Type Mismatch 
Author Message
 VB6 ActiveX Control. CreateDispatch 'ed in VC++6; passed to VB dll; Type Mismatch

I have two components created in VB6 MyServer.dll (an activeX dll),
MyControl.ocx (an activeX control).

I am writing a DLL in VC++6 which uses MyServer and MyControl. I've imported
their type-libraries and made wrapper classes etc. I can create and use the
ActiveX components within the C++ DLL without problems.

However, I'm now trying to CreateDispatch an instance of my VB ActiveX
control directly in the c++ DLL. This seems to work in that I can access its
properties and methods, despite the fact it exists without a visible user
interface _except_ for one problem:

The MyServer class in MyServer.dll holds a property pair:

Private myInstance as MyControlProject.MyControl
Public Property Set ControlInstance(ByVal RHS as object)
    set myInstance = RHS
End Property
Public Property Get ControlInstance() as object
    Set ControlInstance = myInstance
End Property

These set and return an instance of MyControl (an ActiveX control).
If I use only references to MyControl which exist on VB forms, this function
works fine. However if I try to use (in C++)

    _MyServer s;
    _MyControl c;

The function fails in the VB Property Set code on the 'Set
myInstance = RHS' line with a TYPE MISMATCH error. myInstance is strongly
declared as MyControl.

I can use the other methods of s and c without problems.

I notice the same thing also happens if, in a VB exe I use
Dim X as MyControlProject.MyControl
Set X = CreateObject("MyControlProject.MyControl")
    TYPE MISMATCH (though it appears the CreateObject works!)

however I get no errors if I use
Dim X as object.
Set X = CreateObject("MyControlProject.MyControl")

I also note I'm not allowed to use
Dim ... As New MyControl
Set .. = New  MyControl
 in VB.


What is returned by CreateDispatch (or CreateObject) on a VB6 compiled
ActiveX control. It seems it is not the same interface as used in VB to
strongly reference that control in Dim statements??

Most importantly, is there any way I can pass a reference of a VB compiled
ActiveX control instance which has been CreateDispatch'ed in VC++ to a VB
compiled ActiveX dll function parameter expecting a reference to said

hope this makes sense..
    Mike Birtwistle

Tue, 26 Apr 2005 12:23:19 GMT  
 [ 1 post ] 

 Relevant Pages 

1. ? regarding passing data from VC to VB using ActiveX control

2. VB6 ActiveX Dll in VC?

3. My new ActiveX control : CDCs and Different behaviour in VC6, VB6 Design, VB6 Compiled

4. Passing user defined type var between VB and VC

5. Problem using VB 5 activex DLL in a VC++ activex control

6. VB ActiveX Control encapsulated within a VC Control

7. Passing Arguments by Reference from VB to VC ActiveX

8. Passing binary data from VB to VC-MFC-ActiveX

9. VB to VC parameter passing Safearray of UDT's

10. passing NULL pointer from vb to c-dll of type long*

11. VC++ pass object parameter to VB ActiveX DLL

12. Passing Variant array to VB ActiveX DLL


Powered by phpBB® Forum Software