Solved

WithEvents in ActiveX dll

Posted on 2007-03-25
6
469 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
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!

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

691 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