• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 475
  • Last Modified:

WithEvents in ActiveX dll

Hi,

slight problem... I'm making an activex dll and am trying to do something like this:

Diim WithEvents MySomeClass as New SomeClass

Public Function ExportedFunction()
'' do something that triggers SomeEvent
End Function

Private Sub MySomeClass_SomeEvent()
   ' THIS IS NOT TRIGGERED
End Sub

Basically, when i call a function from the dll from my app, the SomeEvent event should be triggered so i can do the processing. The problem is that the event doesn't get triggered.

Please helP!!!

Note: I can't catch the events in my client app b/c it's in C++ and i can't use MFC or ATL and don't wanna do the event sinking in native C++.... Therefore, i want to make a "middleware" dll that handles the event sinking and stores a queue of messages to process that the client can poll.
0
bobbit31
Asked:
bobbit31
  • 4
  • 2
1 Solution
 
rettiseertCommented:
Perhaps i don't understand your question, but to trigger an event you use something like:

'In the class module (dll)

Public Event SomeEvent()

Public Function ExportedFunction()
    RaiseEvent SomeEvent
End Function

'In the form module (exe or dll)

Private WithEvents MySomeClass As SomeClass

Private Sub Form_Load()

    Set MySomeClass = New SomeClass
    MySomeClass.ExportedFunction

End Sub

Private Sub MySomeClass_SomeEvent()
    msgbox "event triggered"
End Sub


0
 
bobbit31Author Commented:
no, i add a reference to a com dll.. this com dll raises events and i want to catch them in my new dll and relay them to the client app:

CLIENT <--> MY DLL <--> COM DLL (i didn't write nor do i have source)

In my dll:
Dim WithEvents ComDll (added reference in project/references)

Public Sub Connect(uid as string, pwd as string)
   ComDll.Connect(uid, pwd)
End Sub

Private Sub ComDll_Connected()
   '' do stuff
End Sub

now I know ComDll.Connect gets called, but the Connected Event isn't getting triggered.
0
 
bobbit31Author Commented:
OK, i've narrowed it down:

The reason the events aren't triggering is b/c the instance of the dll that i use to call is exiting.

If i keep the instance open like so:

ComDll.Connect(...)
MsgBox "wait for event"

then the Connected Event gets triggered as it is supposed to.

So how do i keep the dll "alive" w/o the messagebox and throughout the lifetime of my client app?

(yes, i have set the dll Persistable property though i don't know if that even has any relation to the above issue)

Thanks again!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rettiseertCommented:
mmm... the dll will be kept "alive" as long your code doesn't destroy it

have you tried

ComDll.Connect(...)
DoEvents

?
0
 
bobbit31Author Commented:
>> mmm... the dll will be kept "alive" as long your code doesn't destroy it

Well that's the problem, it doesn't seem as tho it is

>> have you tried

>> ComDll.Connect(...)
>> DoEvents

Yes.

----------------------------------------------------------------

here's how i'm loading the dll in my C++ app, maybe i'm doing something wrong there?

        HMODULE hinst = LoadLibrary("c:\\inimiddleware.dll");
      CoInitialize(NULL);
     
      // Declare the Interface Pointer for your Visual Basic object. Here,
      // _Class1Ptr is the Smart pointer wrapper class representing the
      // default interface of the Visual Basic object.

      // _Class1Ptr ptr;
      // Create an instance of your Visual Basic object, here
      // __uuidof(Class1) gets the CLSID of your Visual Basic object.
        //_Class1Ptr ptr;
       // ptr.CreateInstance(__uuidof(Class1));
                         _Class1Ptr ptr; // The class in my activex dll is named Class1
                         HRESULT hr = ptr.CreateInstance(__uuidof(Class1));

         short st1 = ptr->Connect();


      CoUninitialize();


0
 
bobbit31Author Commented:
EDIT:

HMODULE hinst = LoadLibrary("c:\\inimiddleware.dll");

Remove that line, can't use loadlibrary and getprocaddress b/c the activex dll doesn't export my functions
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now