?
Solved

How to trigger an event from within a bas module

Posted on 2003-03-17
6
Medium Priority
?
348 Views
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)
    Else
        Debug.Print "DDE Initialize Success."
        Initialize = True
    End If

0
Comment
Question by:dbishop
[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
6 Comments
 
LVL 2

Accepted Solution

by:
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
   MyClass.SomeAction
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.
0
 

Author Comment

by:dbishop
ID: 8154930
CD-Softy

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.
   
 
0
 
LVL 2

Expert Comment

by:CD-Softy
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.
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!

 

Expert Comment

by:CleanupPing
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.
0
 
LVL 6

Expert Comment

by:GPrentice00
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:
http://www.experts-exchange.com/help/closing.jsp

GPrentice00
Cleanup Volunteer
0
 
LVL 6

Expert Comment

by:GPrentice00
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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