Solved

WithEvents in ActiveX dll

Posted on 2007-03-25
6
464 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
  • 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

832 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