Solved

WithEvents in ActiveX dll

Posted on 2007-03-25
6
468 Views
Last Modified: 2009-07-29
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
Comment
Question by:bobbit31
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 13

Expert Comment

by:rettiseert
ID: 18788679
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
 
LVL 18

Author Comment

by:bobbit31
ID: 18789534
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
 
LVL 18

Author Comment

by:bobbit31
ID: 18789620
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
Technology Partners: 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!

 
LVL 13

Accepted Solution

by:
rettiseert earned 500 total points
ID: 18790466
mmm... the dll will be kept "alive" as long your code doesn't destroy it

have you tried

ComDll.Connect(...)
DoEvents

?
0
 
LVL 18

Author Comment

by:bobbit31
ID: 18790505
>> 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
 
LVL 18

Author Comment

by:bobbit31
ID: 18790509
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question