Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing a string from VB6 to VB.NET

Posted on 2004-08-04
12
Medium Priority
?
841 Views
Last Modified: 2010-08-05
I have a program written in vb6 that needs to send a string to a program written in VB.NET.  I'm tring to use window messages to do this.  So in the VB6 program I'd have:

SendMessage hwnd, WM_COMMAND, MessageType, "The Message"

and in vb.net I override the WndProc to catch WM_COMMAND messages and then do something with the string:

ProcessMessage(m.lParam)

Of course, that doesn't work.  LParam is an IntPtr, not a string.  So I tried this:

ProcessMessage(System.Runtime.InteropServices.Marshal.PtrToStringAnsi(m.LParam))

which returned junk (I tried PtrToStringUni and PtrToStringAuto with the same result).  I also tried changing the SendMessage declaration.  I origionally used
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

and I've tried changing the lParam declaration to be 'ByRef lParam as String'.  I've also tried making the lParam declaration 'ByVal lParam as Long', and passing the string as 'StrPtr("The Message")'.

Incidentally, I am receiving the MessageType number correctly, and can switch on its value, and I can see that m.lParam.toInt32() is changing each time I get a message.

How do I get the string to go through correcly?
0
Comment
Question by:LastToKnow0
12 Comments
 
LVL 15

Expert Comment

by:SRigney
ID: 11719907
What is the purpose of this?  Maybe we can offer alternatives when we understand the reason for doing this.
0
 
LVL 1

Author Comment

by:LastToKnow0
ID: 11720006
The VB6 program is connected to hardware that collects caller ID information from incoming phone calls.  The VB.NET uses the phone number (or other information, its not always numerical, so I can't just pass it as a long) that was collected and displays information associated with that number.

If there is a better method for getting the information to the vb.net program I'd be interested in that, but I'd really like to know how to get the SendMessage method to work, since I use is in other programs.
0
 
LVL 15

Expert Comment

by:SRigney
ID: 11720081
It sounds like you could make your VB6 program a .dll that raises an event, then catch that event in .Net.

Another method (although probably a poor work-around), is to write the information to a file and make the .net application use a file watcher.  Any time the file changes it will get an event and can read the file to see what changed.

I'm not the one to answer the SendMessage question though, so good luck there.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:LastToKnow0
ID: 11720174
Unfortunately, I'm not able to make changes to the vb6 program on the scale of making it into a dll, and although the file solution would work, its pretty kludgy.
0
 
LVL 15

Expert Comment

by:SRigney
ID: 11720764
0
 
LVL 15

Expert Comment

by:SRigney
ID: 11720792
0
 
LVL 1

Author Comment

by:LastToKnow0
ID: 11720969
I'm afraid not.  I'm not getting an exception as in the first question (and I have tried both of the declarations for SendMessage that are listed there.  And the second is more geared towards sending a string out from .NET, rather than receiving one.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11722592
How is the SendMessage function defined in VB6?

Bob
0
 
LVL 1

Author Comment

by:LastToKnow0
ID: 11722820
Not sure what I can tell you that isn't in the question.  To reiterate:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
0
 
LVL 3

Accepted Solution

by:
Stimphy earned 375 total points
ID: 11723416
Hello,

   Maybe you could just open a TCP Socket and send the data through it.  Granted this isnt the best solution, but it will work.

Regaurds,
Dave
0
 
LVL 1

Author Comment

by:LastToKnow0
ID: 11729494
I like the idea of using a TCP socket.  If no one comes up with a way to send the string through a SendMessage call, I'll give you the points.
0
 
LVL 1

Author Comment

by:LastToKnow0
ID: 11768097
Well, I went ahead and used the TCP socket.  Thanks for the idea.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

916 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