Solved

WithEvents in ActiveX dll

Posted on 2007-03-25
6
459 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Accepted Solution

by:
rettiseert earned 500 total points
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now