Solved

VB6 application writes and I want to read it through dotnet asynchronusly.

Posted on 2013-11-04
6
251 Views
Last Modified: 2013-11-06
I have an very old VB 6 application. It writes all the tracing information (hints &  messages) to a file. I have a dotnet wraper also arround this VB application.

Now I want to display this tracing info on screen through dotnet wraper. How to achieve this?

How can I read the hints & messages generated by VB application, in dot net wraper asynchronusly? Is there any best way that these both can communicate together? I don't want to read the same flat file being generated by the VB code as it can be read only after completing the writting.
0
Comment
Question by:GouthamAnand
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:hjgode
ID: 39624111
If the file is opened exclusive by the VB app, you cannot read of it before the VB app closes the file. Bad programming.

Does the VB app output any text to the console?

Do you have the code of the VB app too?
0
 

Author Comment

by:GouthamAnand
ID: 39624240
Yes, I am having the VB app code. And I am writing the code to write to standard output. But still I am not sure if I will be success in reading it from .net code.

Below 'If' condition is where the hints and messages being logged to flat file.

I am trying to write to standard output.


hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)         ' written by Goutham
    hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)       ' written by Goutham
    hConsoleErr = GetStdHandle(STD_ERROR_HANDLE)        ' written by Goutham
   
    If mbLogHints Then
   
        'iFile = stdout()
'        Open PathConcat(gConCentral.Server.FileServerRoot, "System\" & gConCentral.UID & "Hints.log") For Append As iFile
            ConsolePrint (sHint)                        ' written by Goutham
            'Print #iFile, Y2K(Now) & vbTab & sHint
           
        Close iFile
    End If
   
End Sub

'----------------------------------
'PURPOSE:   Write the string to Console. ' written by Goutham
'----------------------------------
   
Private Sub ConsolePrint(szOut As String)                           ' written by Goutham
    WriteConsole hConsoleOut, szOut, Len(szOut), vbNull, vbNull     ' written by Goutham
End Sub
0
 

Author Comment

by:GouthamAnand
ID: 39624341
Below is my .net code. WorkEngine.exe is the VB application.
below try...catch... block - 2nd 'using..' block I have written.
I haven't get any success till now.


public void DoWork123()
        {
            ProcessStartInfo start = new ProcessStartInfo();
            start.Arguments = "GOSWorkEngineApp.WorkEngine,we1,SQLREG";
           start.FileName = @"C:\Program Files\GOS\WorkEngine.exe";

            start.RedirectStandardOutput = true;
            start.RedirectStandardError = true;
            start.UseShellExecute = false;

            start.WindowStyle = ProcessWindowStyle.Hidden;
            start.CreateNoWindow = true;

            try
            {
                using (Process process = Process.Start(start))
                {
                    processId = process.Id;
                    while (!this.process.HasExited)
                    {
                        using (StreamReader reader = process.StandardOutput)
                        {
                            string result = reader.ReadToEnd();
                            Hinter.Hint.AddHint(result);
                            Console.Write(result);
                        }
                        //Thread.Sleep(1000);
                    }
                    //process.WaitForExit();
                }
            }
            catch (Exception ex)
            {
                Hinter.Hint.AddHint(ex.Message);
                ExceptionManager.Publish(ex);
            }
        }
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 16

Accepted Solution

by:
hjgode earned 500 total points
ID: 39625031
Here is my code to capture the output of an app that writes to console and echos the read lines to the C# app console:

		void makeThumbSheet(string sFile){
			ProcessStartInfo startinfo = new ProcessStartInfo();
			startinfo.Arguments = 
				"-w 480 -h 75 -c 3 -r 4 -i -t -W -O /var/www/video \"" + sFile + "\"";
			startinfo.FileName = "/home/hgode/bin/mtn";
			startinfo.UseShellExecute=false;
			startinfo.CreateNoWindow=true;
			startinfo.LoadUserProfile=true;
			startinfo.RedirectStandardOutput=true;
			Process proc = new Process();
			proc.StartInfo=startinfo;
			Console.WriteLine("++++ creating img");
			proc.Start();

			while(!proc.StandardOutput.EndOfStream){
				string sOut = proc.StandardOutput.ReadLine();
				Console.WriteLine(sOut);
			}

			proc.Close();
		}

Open in new window


You only need to replace the process and arguments (if any).

Does your VB app echo its output to console when you start it manually in a MS-DOS console? Can you redirect the VB app output to a file using:
vbapp.exe >c:\myoutput.txt?
If both is yes, you should be able to capture the output with my above code snippet. Your VB code for console output looks like the one here http://www.angelfire.com/mi4/bvo/vb/vbconio.htm
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 39625369
You could use MSMQ to communicate between VB and .net application.VB application pushes message to MSMQ and .net application constantly listens to the queue and reads the message as it is available. Here is a link on how you can implement it.

http://jwbs-blog.blogspot.com/2009/06/using-msmq-to-communicate-between-net.html

Another approach is to write messages to the file from VB application and read the contents from .net application. Use mutex to make sure the file is accessed (write) by single application at any one point.

In VB, if you use FSO (File System Object) then you would be able to release the file as soon as the filesystem object is closed and set to nothing.
0
 

Author Closing Comment

by:GouthamAnand
ID: 39628251
Thankyou.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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