Sending a message from VB-app to VC-app 
Author Message
 Sending a message from VB-app to VC-app

--------------9BEE2FC75B12CF524A8A207B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

How can I send a user defined message containing text from a VB-app to a
VC-app?
My code is shown below, but I don't get the string over. It is just
empty. Any ideas ?

VB-app:
Global Const WM_USER = 1024
Global Const WM_USER_VBDATA = WM_USER + 63
Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As
String) As Long
Dim par As String

.
.
Private Sub cmdSend_Click()

    Dim hWndLoc As Long
    hWndLoc = FindWindow("Afx:400000:8:14de:0:3f37", 0)
    par = "Test"
    SendMessage hWndLoc, WM_USER_VBDATA, 0, par
End Sub

VC-app:
LRESULT CMyMainFrame::USERVbData(WPARAM wParam, LPARAM lparam)
{
    char *str = (char *)lparam;    // <<<<<The str becomes empty here
    return (LRESULT) TRUE;

Quote:
}

--------------9BEE2FC75B12CF524A8A207B
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
How can I send a user defined message containing text from a VB-app to
a VC-app?
<BR>My code is shown below, but I don't get the string over. It is just
empty. Any ideas ?

<P><U>VB-app:</U>
<BR>Global Const WM_USER = 1024
<BR>Global Const WM_USER_VBDATA = WM_USER + 63
<BR>Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As
String) As Long
<BR>Dim par As String

<P>.
<BR>.
<BR>Private Sub cmdSend_Click()
<BR>&nbsp;
<BR>&nbsp;&nbsp;&nbsp; Dim hWndLoc As Long
<BR>&nbsp;&nbsp;&nbsp; hWndLoc = FindWindow("Afx:400000:8:14de:0:3f37",
0)
<BR>&nbsp;&nbsp;&nbsp; par = "Test"
<BR>&nbsp;&nbsp;&nbsp; SendMessage hWndLoc, WM_USER_VBDATA, 0, par
<BR>End Sub
<BR>&nbsp;

<P><U>VC-app:</U>
<BR>LRESULT CMyMainFrame::USERVbData(WPARAM wParam, LPARAM lparam)
<BR>{
<BR>&nbsp;&nbsp;&nbsp; char *str = (char *)lparam;&nbsp;&nbsp;&nbsp; //
&lt;&lt;&lt;&lt;&lt;The str becomes empty here
<BR>&nbsp;&nbsp;&nbsp; return (LRESULT) TRUE;
<BR>}
<BR>&nbsp;</HTML>

--------------9BEE2FC75B12CF524A8A207B--



Mon, 01 May 2000 03:00:00 GMT  
 Sending a message from VB-app to VC-app

This is a multi-part message in MIME format.

------=_NextPart_000_0047_01BCF11E.68B77E20
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Dear Morten,
you need to send the lParam as Any.
What Visual C++ is expecting is a location in memory where to find the =
string. not the string itself.

    How can I send a user defined message containing text from a VB-app =
to a VC-app?=20
    My code is shown below, but I don't get the string over. It is just =
empty. Any ideas ?=20
    VB-app:=20
    Global Const WM_USER =3D 1024=20
    Global Const WM_USER_VBDATA =3D WM_USER + 63=20
    Declare Function SendMessage Lib "User32" Alias "SendMessageA" =
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef =
lParam As String) As Long=20
    Dim par As String=20
   =20
    .=20
    .=20
    Private Sub cmdSend_Click()=20
     =20
        Dim hWndLoc As Long=20
        hWndLoc =3D FindWindow("Afx:400000:8:14de:0:3f37", 0)=20
        par =3D "Test"=20
        SendMessage hWndLoc, WM_USER_VBDATA, 0, par=20
    End Sub=20
     =20
   =20
    VC-app:=20
    LRESULT CMyMainFrame::USERVbData(WPARAM wParam, LPARAM lparam)=20
    {=20
        char *str =3D (char *)lparam;    // <<<<<The str becomes empty =
here=20
        return (LRESULT) TRUE;=20
    }=20
     =20
   =20

------=_NextPart_000_0047_01BCF11E.68B77E20
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.71.1712.3"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 size=3D2>Dear Morten,</FONT></DIV>
<DIV><FONT size=3D2>you need to send the lParam as Any.</FONT></DIV>
<DIV><FONT size=3D2>What Visual C++ is expecting is a location in memory =
where to=20
find the string. not the string itself.</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 solid 2px; MARGIN-LEFT: 5px; PADDING-LEFT: =
5px">

&lt;<A=20
    =

c.no</A>&gt;...</DIV>How=20
    can I send a user defined message containing text from a VB-app to a =
VC-app?=20
    <BR>My code is shown below, but I don't get the string over. It is =
just=20
    empty. Any ideas ?=20
    <P><U>VB-app:</U> <BR>Global Const WM_USER =3D 1024 <BR>Global Const =

    WM_USER_VBDATA =3D WM_USER + 63 <BR>Declare Function SendMessage Lib =

    &quot;User32&quot; Alias &quot;SendMessageA&quot; (ByVal hwnd As =
Long, ByVal=20
    wMsg As Long, ByVal wParam As Long, ByRef lParam As String) As Long =
<BR>Dim=20
    par As String=20
    <P>. <BR>. <BR>Private Sub cmdSend_Click() <BR>&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;=20
    Dim hWndLoc As Long <BR>&nbsp;&nbsp;&nbsp; hWndLoc =3D=20
    FindWindow(&quot;Afx:400000:8:14de:0:3f37&quot;, 0) =
<BR>&nbsp;&nbsp;&nbsp;=20
    par =3D &quot;Test&quot; <BR>&nbsp;&nbsp;&nbsp; SendMessage hWndLoc, =

    WM_USER_VBDATA, 0, par <BR>End Sub <BR>&nbsp;=20
    <P><U>VC-app:</U> <BR>LRESULT CMyMainFrame::USERVbData(WPARAM =
wParam, LPARAM=20
    lparam) <BR>{ <BR>&nbsp;&nbsp;&nbsp; char *str =3D (char=20
    *)lparam;&nbsp;&nbsp;&nbsp; // &lt;&lt;&lt;&lt;&lt;The str becomes =
empty=20
    here <BR>&nbsp;&nbsp;&nbsp; return (LRESULT) TRUE; <BR>} <BR>&nbsp;=20
</P></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0047_01BCF11E.68B77E20--



Tue, 02 May 2000 03:00:00 GMT  
 Sending a message from VB-app to VC-app

the strings sent by VB are by default BSTR's where alternate characters are
null terminated you need to handle BSTR's and convert to Ctype strings in
your app;
--

Raejsh Parikh - Microsoft Certified Solution Developer
Madras - India
Voice : 91 (44) 642360

======================================================
To get MFC / ACTIVEX / ATL work done by MCSDs for

======================================================



Quote:
> >How can I send a user defined message containing text from a VB-app to a
> >VC-app?
> >My code is shown below, but I don't get the string over. It is just
> >empty. Any ideas ?

> I believe that Windows can only do the clever work of copying data
> between processes for those specific Windows messages that it knows
> might want to do that. For a user defined message it doesn't know that
> you want to pass a string, therefore it won't copy the string between
> processes.

> Have a look at the more general purpose WM_COPYDATA message instead.

> Dave
> ----
> Address is altered to discourage junk mail.
> Remove ".---" for the real address.



Fri, 05 May 2000 03:00:00 GMT  
 Sending a message from VB-app to VC-app

When passing a string to an API from VB, you need to pass the string
ByVal, not ByRef. With strings passed ByRef, VB will pass a pointer
to the BSTR that VB is using. When you pass a string ByVal to an API,
VB will create a temporary LPSTR (i.e. ANSI) and pass that to the
API. Then when the API returns it will copy the LPSTR back into the
internal BSTR.

--
Jeff Kohn
ORCA Technologies, INC
jkohn "at" orca "dot" net



Quote:
> How can I send a user defined message containing text from a VB-app
to a
> VC-app?
> My code is shown below, but I don't get the string over. It is just
> empty. Any ideas ?

> VB-app:
> Global Const WM_USER = 1024
> Global Const WM_USER_VBDATA = WM_USER + 63
> Declare Function SendMessage Lib "User32" Alias "SendMessageA"
(ByVal
> hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef
lParam As
> String) As Long
> Dim par As String

> .
> .
> Private Sub cmdSend_Click()

>     Dim hWndLoc As Long
>     hWndLoc = FindWindow("Afx:400000:8:14de:0:3f37", 0)
>     par = "Test"
>     SendMessage hWndLoc, WM_USER_VBDATA, 0, par
> End Sub

> VC-app:
> LRESULT CMyMainFrame::USERVbData(WPARAM wParam, LPARAM lparam)
> {
>     char *str = (char *)lparam;    // <<<<<The str becomes empty
here
>     return (LRESULT) TRUE;
> }



Sun, 14 May 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VB(app.path) VB C#(app.path) HOW-TO

2. sending messages between apps

3. Break not seen when another app sends message

4. Sending a message from one app to another on NT

5. Sending message to CPropertySheet crashes app in Release

6. [ Access violation sending message in multi-threaded app! ]

7. Trying to send a message from one app to another

8. Sending a message from one app to another on NT

9. Sending message to a MFC app.

10. Send message to another App

11. Sending Mail with NEWMAIL from VC Console App

12. Drag drop from VB app to MFC app problem

 

 
Powered by phpBB® Forum Software