Solved

VB5 handling user messages from other apps

Posted on 1997-11-20
8
144 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 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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.
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…
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…

896 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

16 Experts available now in Live!

Get 1:1 Help Now