Solved

VB5 handling user messages from other apps

Posted on 1997-11-20
8
143 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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 …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

757 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

21 Experts available now in Live!

Get 1:1 Help Now