Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB5 handling user messages from other apps

Posted on 1997-11-20
8
Medium Priority
?
160 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
  • 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 680 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
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: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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

885 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