Solved

Events of VB handled in VC and vice versa

Posted on 2002-07-25
8
457 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
[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
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
Independent Software Vendors: 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!

 

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
 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

717 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