Solved

Events of VB handled in VC and vice versa

Posted on 2002-07-25
8
440 Views
Last Modified: 2011-09-20
Hi,
My problem is.
I have a VB activeX exe raising some events and which are required to be handled in VC++ component but i dont know how to do it.
I also want a VC++ component raising an event and which is handled in VB.
PLease give me some sample code as i already have gone through many theories but of no use so ssample code is required to perform both the tasks.
0
Comment
Question by:iamvikky
8 Comments
 
LVL 5

Expert Comment

by:RainUK
ID: 7176650
What sort of data do you want to pass between the two exe's. If it is simply a pair of long values, then you could just Broadcast Windows messages. I did a similar thing between a C++ DLL and a VB Client application.

In both your applications you will register a windows message:

In VB app:-

lngEventMsgFromC++App = RegisterWindowMessage("MyWindowsEventMsgFromC++")
lngEventMsgToC++App = RegisterWindowMessage("MyWindowsEventMsgToC++")

Now you will also have to subclass this applications messages using (using APIs SetWindowLong(Hwnd,GWL_WNDPROC,lpPrevWndProc) ).

So in the WindowProc API you will have something like this:

If uMsg = lngEventMsgFromC++App Then
   ' This windows message has been fired by your C++ App
   ' so deal with it here, you can pass two parameters
   ' wParam and lParam, so you will have to design your
   ' own method of deciphering what you send in the event
End If

Now to raise an event in your VB program so that your C++ program will receive an event you will need to use the API

BroadcastSystemMessage(BSF_SENDNOTIFYMESSAGE + BSD_IGNORECURRENTTASK,lngRecipients, lngEventMsgToC++App, wParam, lParam)

I use this because it is system wide and my VB app was an NT service.

Now in your C++ application you will have to do the same (Select case the windows messages to the app)to receive messages, you must also register the same two windows message in your C++ app:

UINT uEventMsgToC++App
UINT uEventMsgFromC++App

uEventMsgToC++App = RegisterWindowMessage("MyWindowsEventMsgToC++")

 and when you want to raise an event to the VB app, you could use the following sub routine:

VOID BroadcastEvent(long wParam, long lParam)
{
   DWORD dwRec = 0;
   DWORD *lpdwRecipients = NULL;
   
   uEventMsgFromC++App = RegisterWindowMessage("MyWindowsEventMsgFromC++")

   dwRec = static_cast<DWORD>(BSM_APPLICATIONS + BSM_ALLDESKTOPS);
   lpdwRecipients = &dwRec;

   BroadcastSystemMessage(BSF_SENDNOTIFYMESSAGE,lpdwRecipients,uEventMsgFromC++App,wParam,lParam)

}

---------- Hope this may have sparked some ideas ------






0
 

Author Comment

by:iamvikky
ID: 7176706
Thanks RainUK,
But I my problem is something else and is much simpler then what u thought.I'll explain u in detail.:
I have a VB activeX exe which raises an event with a Recordset(of ADO) having some some records picked from the database. Now my requirement is to handle that raised event in a VC++ component. I cannot change that VB ActiveX exe as it part of the existing system which is raising this event to all other VB clients . I want to introduce a VC client which can also handle the same event.

I tried raising an event with VB activeX dll and handling in VC it is working fine but I am not been able to do the same with VB active X exe and handling it in VC.
Now if you can help me in this......
0
 
LVL 5

Expert Comment

by:RainUK
ID: 7176724
If the ActiveX EXE (The one you cannot change) can fire events which is trapped by other VB clients, then can you not create another VB client to receive those events and pass them onto the VC app?

Basically you create another VB.exe app which sits between the two components, in a sense a VB bit of middleware which handles messaging between the two components.
0
 

Author Comment

by:iamvikky
ID: 7176760
my problem is related to event handling in VC not to look for work arounds ...secondly the kind of system i am working with requires much faster speed and by adding more layers that will not serve the purpose..
So if you can provide me with very basic event hadling in VC as we do in VB then its fine....as my requirement is just the same..i can provide you with the sample of ActiveX exe's (which is raising the event)code and if you can provide me with its client in VC..

CODE:
just paste this code in the class module of activeX exe project of vb and then compile it to make exe..



Option Explicit

Public Event TimeUpdate(sTime As String)

Public Sub CallMeBack()
    RaiseEvent TimeUpdate(Time())
   
End Sub

Public Function ServerTime() As String
   
    ServerTime = Time
   
End Function


'''Code ends here ...

Now i want to trap this even in the VC component directly without any middleware...If you can help...

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 5

Expert Comment

by:RainUK
ID: 7176815
Sorry I am out of ideas on this one. If you can't change the ActiveX exe in anyway which is raising the event. I am a VB programmer at heart so I suggest you try posing this question to the C++ programmers section of the forum.

Good luck
0
 
LVL 4

Expert Comment

by:chabaud
ID: 7180029
Hi,

What is you VC environment ?

If you are using MFC, try to add a class for your component "From a type library" with the MFC ClassWizard and select the .exe file.

EC
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8040615
Hi iamvikky,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

iamvikky, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8095722
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

708 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

14 Experts available now in Live!

Get 1:1 Help Now