Click here to Skip to main content
15,920,053 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralFormatting datagrids Pin
evertbylt24-Aug-05 4:21
evertbylt24-Aug-05 4:21 
GeneralRe: Formatting datagrids Pin
Dave Kreskowiak24-Aug-05 5:43
mveDave Kreskowiak24-Aug-05 5:43 
GeneralComboboxes in datagrid Pin
evertbylt24-Aug-05 4:16
evertbylt24-Aug-05 4:16 
GeneralAuto Setup for Datagrids Pin
RichardBerry24-Aug-05 4:10
RichardBerry24-Aug-05 4:10 
Generalretrive data from datagrid Pin
elcheah24-Aug-05 3:14
elcheah24-Aug-05 3:14 
GeneralRe: retrive data from datagrid Pin
Dave Kreskowiak24-Aug-05 5:36
mveDave Kreskowiak24-Aug-05 5:36 
GeneralConnection time out Pin
Rizwan Bashir24-Aug-05 0:06
Rizwan Bashir24-Aug-05 0:06 
GeneralSendmessage from VB6 to vb.NET, please help. Pin
elgerm23-Aug-05 23:36
elgerm23-Aug-05 23:36 
Hi,

I'm trying to send a windows message from vb6 to a vb.net app. The problem is that I can recieve a message, but the string I send with it is not recieved correctly by the vb.net app. When I try to put it back into a string again I get garbage.

Here is some code from the sending app (vb6):
<code>Private Sub cmdSendData_Click()
Dim sString As String
Dim lHwnd As Long
Dim cds As COPYDATASTRUCT
Dim buf(1 To 255) As Byte

sString = Trim$(txtString)
If sString = "" Then Exit Sub
'
' Get the handle of the target application's visible window.
'
lHwnd = FindWindow(vbNullString, cWINDOW_TITLE)
'
' Copy the string into a byte array,
' converting it to ASCII. Assign lpData
' the address of the byte array.
'
Call CopyMemory(buf(1), ByVal sString, Len(sString))
With cds
.dwData = 3
.cbData = Len(sString) + 1
.lpData = VarPtr(buf(1))
End With
'
' Send the string.
'
Call SendMessage(lHwnd, WM_COPYDATA, Me.hwnd, cds)
End Sub</code>

And here is the recieving app(vb.net):
<code> Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = MainForm.WM_COPYDATA Then
Dim data As CopyData
Dim message As String

' get the data...
data = CType(m.GetLParam(GetType(CopyData)), CopyData)
message = Marshal.PtrToStringAuto(data.lpData, data.cbData \ Marshal.SystemDefaultCharSize)

' add the message
Messages.Items.Add(String.Format("{0}: {1}", DateTime.Now.ToShortTimeString(), message))

' let them know we processed the message...
m.Result = New IntPtr(1)
Else
MyBase.WndProc(m)
End If
End Sub

Private Const WM_COPYDATA As Integer = &H4A

<StructLayout(LayoutKind.Sequential)> _
Private Structure CopyData
Public dwData As IntPtr
Public cbData As Integer
Public lpData As IntPtr
End Structure</code>

If I send the same message from a vb.net app then everything works.
Can anyone tell me what I'm doing wrong?

Thanks!
GeneralRe: Sendmessage from VB6 to vb.NET, please help. Pin
elgerm24-Aug-05 1:43
elgerm24-Aug-05 1:43 
GeneralI want to ask for Visual Basic Pin
chuyendd23-Aug-05 23:08
chuyendd23-Aug-05 23:08 
GeneralRe: I want to ask for Visual Basic Pin
Colin Angus Mackay23-Aug-05 23:32
Colin Angus Mackay23-Aug-05 23:32 
GeneralRe: I want to ask for Visual Basic Pin
toxcct24-Aug-05 1:19
toxcct24-Aug-05 1:19 
GeneralRe: I want to ask for Visual Basic Pin
Rizwan Bashir24-Aug-05 2:04
Rizwan Bashir24-Aug-05 2:04 
GeneralDI want to ask for Visual Basic Pin
chuyendd23-Aug-05 23:07
chuyendd23-Aug-05 23:07 
GeneralI want to ask for Visual Basic Pin
Anonymous23-Aug-05 22:50
Anonymous23-Aug-05 22:50 
GeneralRe: I want to ask for Visual Basic Pin
toxcct23-Aug-05 23:03
toxcct23-Aug-05 23:03 
GeneralVisual Basic Data Report Pin
VPNampoothiri23-Aug-05 22:09
VPNampoothiri23-Aug-05 22:09 
Generaloverriding ListView's Paint event Pin
grambowk23-Aug-05 21:48
grambowk23-Aug-05 21:48 
GeneralRe: overriding ListView's Paint event Pin
Dave Kreskowiak24-Aug-05 5:33
mveDave Kreskowiak24-Aug-05 5:33 
GeneralRe: overriding ListView's Paint event Pin
grambowk24-Aug-05 8:15
grambowk24-Aug-05 8:15 
Generalasp page Pin
ybasha23-Aug-05 17:00
ybasha23-Aug-05 17:00 
GeneralRe: asp page Pin
Rizwan Bashir24-Aug-05 2:08
Rizwan Bashir24-Aug-05 2:08 
GeneralVb.Net Small Project Pin
VBUser7723-Aug-05 14:55
VBUser7723-Aug-05 14:55 
GeneralRe: Vb.Net Small Project Pin
rwestgraham23-Aug-05 15:28
rwestgraham23-Aug-05 15:28 
QuestionApplication Login Suggestions? Pin
DEWright_CA23-Aug-05 12:58
DEWright_CA23-Aug-05 12:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.