Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to trigger an event from within a bas module

Posted on 2003-03-17
Medium Priority
Last Modified: 2008-02-01
I have a DLL. Inside the DLL I have a class module and bas module.
I am using the DDEInitialize api routine. It uses a property that points to a bas module function.
When this bas module function runs I need to pass a value back up to the parent program. You can't create a event from within the bas module which is how I've been passing information back to the parent program. How can I pass some information back to a parent program if the function resides inside a bas module within a DLL? If I move the DDECALLBACK into the class module I get an error since the api expects a public function pointer.

Is there a way to make a pointer to a function that resides in a class? I'm lost on this one.

Example code:

Public Declare Function DdeInitialize Lib "user32" Alias "DdeInitializeA" _
    (pidInst As Long, _
    ByVal pfnCallback As Long, _
    ByVal afCmd As Long, _
    ByVal ulRes As Long) As Integer

    If DdeInitialize(g_lInstID, AddressOf DDECallback, APPCMD_CLIENTONLY Or MF_SENDMSGS Or MF_POSTMSGS, 0) Then
        Debug.Print "DDE Initialize Failure."
        RaiseEvent evtMessage(TranslateError)
        Debug.Print "DDE Initialize Success."
        Initialize = True
    End If

Question by:dbishop

Accepted Solution

CD-Softy earned 1000 total points
ID: 8154882
You need to raise an event in the class to pass the value to the app. The function that raises the event should be called from the modules callback function, like this..

In your class module...

'Declarations Section
Public Event MyAction(Msg as String)

Friend SomeAction()
   'this will raise the event in the app that has declared the class
   RaiseEvent MyAction(evtMessage(TranslateError))
End Function

'In the Callback fuction of your bas module

Private Function DDECallback()
   'your code
   Dim MyClass as New YourClass
End Function

Now in your app, you need to
Dim WithEvents MyObject as YourClass
You will then get the event with the value as a parameter.

Good Luck.

Author Comment

ID: 8154930

The app and the DLL are separate apps.
Like this:

App 1, DLL
   Module 1 with callback function
   Class 1 with event

App 2. EXE
   Here is where I need to know when the event trips.
   The Dim WithEvents MyObject as YourClass
   only works if it is in App 1 from my tests so far.

Expert Comment

ID: 8155015
This should still work, regardless of where the DLL is referenced from, providing you set a reference to that DLL from your EXE.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Expert Comment

ID: 8532165
Hi dbishop,
This old question (QID 20553850) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.

Expert Comment

ID: 8982922
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in a week or two.  I would appreciate any comments by the experts that would help me in making a recommendation.
It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:

Cleanup Volunteer

Expert Comment

ID: 9034007
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept CD-Softy's comment as Answer

Please leave any comments here within the next seven days.


Cleanup Volunteer

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

564 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