Solved

VB5 handling user messages from other apps

Posted on 1997-11-20
8
149 Views
Last Modified: 2008-02-26
I have a visual c++(5.0) app that needs to send a message to a visual basic(5.0) app for processing.  Is it possible for me to direct the message to the correct vb function through a message-map?  Is DDE an option?  I have been told that DDE is being avoided and OLE is the standard.  I am trying to avoid making the c++ project an OLE object.  What is the recommended solution for interprocess communication from a c++ app to a vb app without registering the object?
Getting the WM_COPYDATA message to work would be sufficient.
0
Comment
Question by:crl
[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
  • 5
  • 3
8 Comments
 

Author Comment

by:crl
ID: 1441657
Edited text of question
0
 

Author Comment

by:crl
ID: 1441658
Adjusted points to 150
0
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 170 total points
ID: 1441659
You can create your type of message and send it to a vb window. Then, in VB, using AdressOf and peek the message and proccess it.
0
Revamp Your Training Process

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

 

Author Comment

by:crl
ID: 1441660
TO MikeP:
I really need more detail for this answer to be helpful.
By creating my type of msg, do you mean something like
#define MY_MSG WM_USER + 100?
How exactly do I peek the msg?  Call PeekMessage frequently?
Can I pass a string as lparam from c++ with the msg and read it in vb?
thanks,
 
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1441661
By creating a new message I do mean a new number fro that message. You can pass any argument via lParam and wParam. To catch the message from VB, do the following:
In Globals:
Dim m_proc as long

In  Form_Load:
m_Proc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)

Function WindowProc(hwnd as long, uMsg as long, wParam as long, lParam as long) as long

'Proccess your message.
'If lParam is a pointer to a string, use MoveMemory to retrive it. wParam must be the size of that string
Dim Buf as string *256
MoveMemory(lParam, Buf, wParam)

WindowProc = CallWindowProc(m_Proc, hwnd, uMsg, wParam, lParam)
End function

0
 

Author Comment

by:crl
ID: 1441662
MikeP - thanks, I am trapping the message now, but I am still having problems copying the string that lparam points to.  Can you seethe problem with this code:

Public Declare Sub MoveMemory Lib "kernel32" Alias _ "RtlMoveMemory" (dest As Any, ByVal Source As Long, _
ByVal length As Long)

Function WindowProc(ByVal hw As Long, _
                    ByVal uMsg As Long, _
                    ByVal wParam As Long, _
                    ByVal lParam As Long) As Long
   
    If uMsg = UM_ACCOUNT_SELECTED Then
        Dim Buf As String * 256
        MoveMemory Buf, lParam, wParam
        MsgBox "ACCOUNT # = " & Buf
    Else
        WindowProc = CallWindowProc(lpPrevWndProc, hw, _
                                   uMsg, wParam, lParam)    
    End If
End Function

I see that I am passing wparam as the length of the lparam string correctly and that the address(lparam) is being passed correctly.  The MoveMemory statement is having no effect.  In fact I am having trouble using MoveMemory for local data in the vb project.

thanks for any help that you can give me.

Chris
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1441663
Try this declare:
Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef hpvDest As Any, ByVal hpvSource As Any, ByVal cbCopy As Long)
0
 

Author Comment

by:crl
ID: 1441664
I couldn't get MoveMemory to work.  I bought a good book "Hardcore Visual Basic" which has helped me by giving good explanations and samples.  I have filemapping working as shared memory.  Everything is looking good now.

Thanks MikeP
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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 Month11 days, 2 hours left to enroll

631 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