Question for the experts (ActiveX DLL's without references) 
Author Message
 Question for the experts (ActiveX DLL's without references)

Hi there. I'm having rather annoying problems getting ActiveX DLLs to have
two-way communications with a seperate .EXE

My problem stems from the fact I want the ActiveX DLL to talk to my EXE,
WITHOUT having to add a Reference from the .EXE to the .DLL. The eventual
goal is to have a host application which can remain unmodified as DLL
modules are added to it.

Two projects (P1 and P2).
P1 is a standard EXE (the host)
P2 is an ActiveX DLL (a module)

I can create a class in P2 called clsDoodle:
Public Event tstEvent()
Public Sub tstSub()
    RaiseEvent tstEvent
End Sub

And create an instance of it in P1:
Private objDoodle as Object
Set objDoodle = CreateObject("P2.clsDoodle")

But, then I can't handle the events of the clsDoodle instance. I need
something like this:
Private WithEvents objDoodle as Object
Set objDoodle = CreateObject("P2.clsDoodle")

But, of course, as VB doesn't know the _type_ of the Object, it doesn't know
what events it can raise, and hence throws a wobbly when compiling.

One solution is to:
Private WithEvents objDoodle as P2.clsDoodle
Set objDoodle = CreateObject("P2.clsDoodle")

But for this to work I need to put a reference to P2 in P1. As I want to be
able to add extra modules (P3, P4 etc...) without modifying the host
application, this isn't a valid solution.

My next thought was to have a common interface between the projects, so I
created a new project called Interface, and a class called IDoodle:
Public Event tstEvent()
Public Sub tstSub()
End Sub

Adding references to Interface to both P1 and P2, I alter P2 (the DLL) to:
Implements Interface.IDoodle
Public Event tstEvent()
Private Sub Interface_tstSub()
    RaiseEvent tstEvent
End Sub

The idea is that all my modules will Implement Interface.IDoodle, so the
host has a common interface to all modules (makes sense to me).

And alter P1 (the EXE) as follows:
Private WithEvents objDoodle as Interface.IDoodle
Set objDoodle = CreateObject("P2.clsDoodle")

Which ALMOST works. But then it tells me that I can't use the events of a
class which is implementing another class with Events. ARRRGGGHHHHH!!!!

Is there ANY way round this??? I NEED two-way (events & methods)
communication, without adding references to the host application.

Any help greatefully received.

Ta,
Dave.



Wed, 18 Jun 1902 08:00:00 GMT  
 Question for the experts (ActiveX DLL's without references)
Hello David,

Quote:
>My problem stems from the fact I want the ActiveX DLL to talk to my EXE,
>WITHOUT having to add a Reference from the .EXE to the .DLL. The eventual
>goal is to have a host application which can remain unmodified as DLL
>modules are added to it.

        I have found only one solution to this.  Create a class called
CEventProvider.  This class would have a single method (.RaiseEvent)
and a single event (_RaisedEvent).  Both of these items would have two
parameters.... EventName (As String) and EventArgs (As Variant).

(All code listed below is untested)

---- In P1.EXE --------------------------------------------
Private WithEvents EventProvider    As P2.CEventProvider

Dim objWhatever          As Object

Set EventProvider = New P2.CEventProvider

Set objWhatever = CreateObject("P1.CDoodle")
Set objWhatever.EventProvider = EventProvider

...Do stuff here...

Set objWhatever.EventProvider = Nothing
Set objWhatever = Nothing
-----------------------------------------------------------

---- In P2.DLL --------------------------------------------
Class CDoodle

Private mEventProvider     As CEventProvider

Public Sub tstSub()

        mEventProvider.RaiseEvent "MyEventName", 6
End Sub

Class CEventProvider

Public Sub RaisedEvent(ByVal EventName As String, _
                       ByRef EventArgs As Variant)

        Raise RaisedEvent(EventName, EventArgs)
End Sub
-----------------------------------------------------------

        So, basically you will create a CEventProvider object in your EXE,
then you would create a CDoodle object in your EXE.  Then you would
give your CDoodle object a reference to your CEventProvider object.
From your CDoodle object you could then raise an event in your EXE by
calling the RaiseEvent method of your CEventProvider object.  Note
that the type for EventArgs in a variant, so you can use an array when
more than one argument in required in the event.

        The above sample code has the CEventProvider and CDoodle classes
in the same DLL.  When you actually write this code yourself you will
want to place these classes in separate DLLs.  Each of your P1, P2,
P3, etc. DLL's will need to reference the DLL that contains the
CEventProvider class as will your EXE project.  I keep my
CEventProvider class in a DLL that I use in virtually ALL my VB
projects.

        I would also recommend that you use interfaces for your CDoodle
classes.... Just add:

Public Property Set EventProvider(ByRef NewValue As CEventProvider)

...as part of the interface so that you can avoid late binding
entirely.

Hope this helps,
Len
---
Len Weaver



Wed, 18 Jun 1902 08:00:00 GMT  
 Question for the experts (ActiveX DLL's without references)
From the main program call the DLL with a Class as a parameter.

eg: Call MyDllSetClass( TheClass )

Give the Class *known* functions eg: 'Activate'

From the DLL :
     Call MyCopyOfTheClass.Activate( Param1, Param2 )

Of course all parameter checking is down to you, also ensuring that
the class actually has the 'assumed' function.

This also works fine for ActiveX DLLs

On Fri, 10 Nov 2000 18:13:07 -0000, "David Walker"

Quote:

>Hi there. I'm having rather annoying problems getting ActiveX DLLs to have
>two-way communications with a seperate .EXE

>My problem stems from the fact I want the ActiveX DLL to talk to my EXE,
>WITHOUT having to add a Reference from the .EXE to the .DLL. The eventual
>goal is to have a host application which can remain unmodified as DLL
>modules are added to it.

>Two projects (P1 and P2).
>P1 is a standard EXE (the host)
>P2 is an ActiveX DLL (a module)

>I can create a class in P2 called clsDoodle:
>Public Event tstEvent()
>Public Sub tstSub()
>    RaiseEvent tstEvent
>End Sub

>And create an instance of it in P1:
>Private objDoodle as Object
>Set objDoodle = CreateObject("P2.clsDoodle")

>But, then I can't handle the events of the clsDoodle instance. I need
>something like this:
>Private WithEvents objDoodle as Object
>Set objDoodle = CreateObject("P2.clsDoodle")

>But, of course, as VB doesn't know the _type_ of the Object, it doesn't know
>what events it can raise, and hence throws a wobbly when compiling.

>One solution is to:
>Private WithEvents objDoodle as P2.clsDoodle
>Set objDoodle = CreateObject("P2.clsDoodle")

>But for this to work I need to put a reference to P2 in P1. As I want to be
>able to add extra modules (P3, P4 etc...) without modifying the host
>application, this isn't a valid solution.

>My next thought was to have a common interface between the projects, so I
>created a new project called Interface, and a class called IDoodle:
>Public Event tstEvent()
>Public Sub tstSub()
>End Sub

>Adding references to Interface to both P1 and P2, I alter P2 (the DLL) to:
>Implements Interface.IDoodle
>Public Event tstEvent()
>Private Sub Interface_tstSub()
>    RaiseEvent tstEvent
>End Sub

>The idea is that all my modules will Implement Interface.IDoodle, so the
>host has a common interface to all modules (makes sense to me).

>And alter P1 (the EXE) as follows:
>Private WithEvents objDoodle as Interface.IDoodle
>Set objDoodle = CreateObject("P2.clsDoodle")

>Which ALMOST works. But then it tells me that I can't use the events of a
>class which is implementing another class with Events. ARRRGGGHHHHH!!!!

>Is there ANY way round this??? I NEED two-way (events & methods)
>communication, without adding references to the host application.

>Any help greatefully received.

>Ta,
>Dave.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Q: Referencing ActiveX DLL's

2. References for ActiveX dll's utilizing dsn-less connections

3. Double Reference Entries for user created ActiveX DLL's

4. What's the differance between a ActiveX.dll and regular dll's

5. Question re. ActiveX DLL's and Arrays

6. persistance question on ActiveX DLL's

7. Registering an ActiveX server without apearing in the References list

8. Including a DLL reference file without using the screen

9. Compiled Dll's Exe's and references

10. Question for experts (ActiveX Datasource Problem):

11. Creating Menu's without 3rd party DLL's

12. ActiveX DLL events won't fire when DLL shows Modal Form

 

 
Powered by phpBB® Forum Software