Link to home
Start Free TrialLog in
Avatar of crl
crl

asked on

VB5 handling user messages from other apps

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.
Avatar of crl
crl

ASKER

Edited text of question
Avatar of crl

ASKER

Adjusted points to 150
ASKER CERTIFIED SOLUTION
Avatar of MikeP090797
MikeP090797

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of crl

ASKER

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

Avatar of crl

ASKER

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
Try this declare:
Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef hpvDest As Any, ByVal hpvSource As Any, ByVal cbCopy As Long)
Avatar of crl

ASKER

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