|
-
Mar 28th, 2003, 11:13 PM
#1
Thread Starter
New Member
Who can solve this problem?
Here's the situation. I have an old program in VB6 which I intend to keep as it is. Upgrading it to .NET would be just too troublesome, so that's not an option. What I'd like to accomplish is to develop a program in VB.NET that will allow me to read strings from the old program. For example, I'd like the old VB6 program to send its version (in string type) to the VB.NET program, which in trun will show the version on the VB.NET form (or just store it in the memory).
Is there any way of doing this? I know how to do this between two VB6 programs but I just can't figure it out for .NET. Does anyone here know anything about this? Any reference to a site or examples that I can follow would be just great!
Thanks in advance!
Eric.
What is finite, but boundaryless?
-
Mar 29th, 2003, 01:37 PM
#2
PowerPoster
The easiest way would be to just create a txt file with the old app and print it's version in it using App.Major & "." & App.Minor.
Then just read from the text file with your VB .net version.
The Harder way would be to use API. Namely SendMessagebystring, SendMessagelong,FindWindow,FindWindowex to find your VB .net project and send the string to it.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Mar 31st, 2003, 02:01 PM
#3
Thread Starter
New Member
Originally posted by Arc
The Harder way would be to use API. Namely SendMessagebystring, SendMessagelong,FindWindow,FindWindowex to find your VB .net project and send the string to it.
Well, how do I exactly achieve this? Do you have any examples for it?
I was thining of using TCP to send/receive within localhost since both will be run on the same machine.
Thanks.
What is finite, but boundaryless?
-
Apr 1st, 2003, 12:28 AM
#4
PowerPoster
This example i made uses Notepad. But it's fairly simple to change it to any program. You just need an API spy program to the title of the program(which is usualy what the title bar says).
All you need is 3 buttons and a textbox
Put this in a module
VB Code:
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Declare Function SendMessageByNum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Const WM_SETTEXT = &HC
Public Const WM_CLOSE = &H10
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
Public Const GW_HWNDNEXT = 2
Function GetText(Handle)
GetTrim = SendMessageByNum(Handle, 14, 0&, 0&)
TrimSpace$ = Space$(GetTrim)
GetString = SendMessageByString(Handle, 13, GetTrim + 1, TrimSpace$)
GetText = TrimSpace$
End Function
This goes in 3 different buttons.. 1 button sends text to Notepad, one gets text from Notepad and one closes Notepad.
VB Code:
Private Sub Close_Click()
Dim notepad As Long, editx As Long
notepad = FindWindow("notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
Call PostMessage(notepad, WM_CLOSE, 0, 0)
End Sub
Private Sub Gettxt_Click()
Dim notepad As Long, editx As Long
notepad = FindWindow("notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
TheText = GetText(editx)
Text1 = TheText
End Sub
Private Sub SetTxt_Click()
Dim notepad As Long, editx As Long
notepad = FindWindow("notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
Call SendMessageByString(editx, WM_SETTEXT, 0, Text1)
End Sub
Just type text into your textbox and click the Settxt button and it will put the text into notepad etc...
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Apr 1st, 2003, 02:24 AM
#5
Junior Member
A lot depends on your exact needs. If you just want a few properties then there's an easy solution. If you want the two apps to be continuously talking to each other, there are other more complicated solutions.
For the example of version info you could put a new (multiuse) class in your old VB6 project. Have this class initialise with the version information you're interested in.
Get the .net application to create an instance of this class and read the properties.
Gets round an awful lot of API messing around.
If there's more info, then just put more properties on the class.
If it's a bit more dynamic than that, you could have the class raise events.
There's also the possibility of callbacks. Define an interface class in your VB6 project and get it to make calls through this interface. Have a .net class implement this interface and get it to pass a reference to your VB app.
Dave
Last edited by daughey; Apr 1st, 2003 at 02:30 AM.
-
Apr 1st, 2003, 06:32 PM
#6
Thread Starter
New Member
Solved
Actually, I used .NET's Remoting service to find the solution. I made a COM class for the vb6 application to access, in which an object is created virtually (referenced from the server). From the object, I made a simple call to change the variable's value, that sits on the server side. And voila, it's done.
Much thanks to everyone who tried to help me. I really appreciated your help!
You all are the best!
Eric.
What is finite, but boundaryless?
-
Sep 1st, 2007, 10:54 PM
#7
New Member
Re: Who can solve this problem?
Sorry to resurrect such an ancient post, but I'm having trouble figuring out how to do this exact thing, but in VB.net (VS2005 specifically) instead of VB6. That is, I need to know how to put text into notepad and get text back from it and also how to close it would be nice as well. I already know how to launch it, I mostly just need to know how to control its text a bit.
If anyone can help, I would be most appreciative 
Thanks in advance.
 Originally Posted by Arc
This example i made uses Notepad. But it's fairly simple to change it to any program. You just need an API spy program to the title of the program(which is usualy what the title bar says).
All you need is 3 buttons and a textbox
Put this in a module
VB Code:
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Declare Function SendMessageByNum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Const WM_SETTEXT = &HC
Public Const WM_CLOSE = &H10
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
Public Const GW_HWNDNEXT = 2
Function GetText(Handle)
GetTrim = SendMessageByNum(Handle, 14, 0&, 0&)
TrimSpace$ = Space$(GetTrim)
GetString = SendMessageByString(Handle, 13, GetTrim + 1, TrimSpace$)
GetText = TrimSpace$
End Function
This goes in 3 different buttons.. 1 button sends text to Notepad, one gets text from Notepad and one closes Notepad.
VB Code:
Private Sub Close_Click()
Dim notepad As Long, editx As Long
notepad = FindWindow("notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
Call PostMessage(notepad, WM_CLOSE, 0, 0)
End Sub
Private Sub Gettxt_Click()
Dim notepad As Long, editx As Long
notepad = FindWindow("notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
TheText = GetText(editx)
Text1 = TheText
End Sub
Private Sub SetTxt_Click()
Dim notepad As Long, editx As Long
notepad = FindWindow("notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
Call SendMessageByString(editx, WM_SETTEXT, 0, Text1)
End Sub
Just type text into your textbox and click the Settxt button and it will put the text into notepad etc...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|