fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Problem with class VO.Console

Problem with class VO.Console 4 months 1 week ago #11812

  leon_ts's Avatar Topic Author leon_ts Offline Posts: 33
Hi,

Faced a problem in the work of the VO.Console class. The Write() method does not print text to the console. With ILSpy I investigated this method, and apparently the problem is in the FileStream.Write() method (FWrite -> XSharp.IO.File.writeBuf), with the console handle argument passed to it. The handle of console in the VO.Console class is obtained as: hConOut := GetStdHandle(STD_OUTPUT_HANDLE).

There are two problems that I noticed (but maybe I overlooked or misunderstood something):

1. The XSharp.IO.File.writeBuf method receives a FileStream object from the cache (streams dictionary) by handle (findStream() method), but does not add this key to streams anywhere. But maybe I just did not understand the code.
2. The FileStream class does not work with the console handle obtained using GetStdHandle(STD_OUTPUT_HANDLE). Throws an exception. If you pass it a handle obtained, for example, from CreateFile(), then FileStream works fine.

The WriteFile() function works with the console handle without any problems:
hConOut := GetStdHandle(STD_OUTPUT_HANDLE)
WriteFile(hConOut, String2Psz("abc"), 3, @nWritten, NULL)

Best regards,
Leonid

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 4 months 1 week ago #11813

  robert's Avatar robert Offline Posts: 1540
Leonid,
The Console class uses FWrite() and uses a native Win32 file handle for the fWrite(), That is indeed an error.
A similar problem can be found in Console.Read()
We will change that in the next build.
I am not sure what the best solution is in this case. We can use the StandardInput, StandardError and StandardOutput properties from the Process class or use the Win32 functions to read/write to the native handles.
What would you prefer ?
Or should we rewrite the whole class on top of System.Console ?

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 4 months 1 week ago #11814

  wriedmann's Avatar wriedmann Away Posts: 2188
Hi Robert,

Or should we rewrite the whole class on top of System.Console ?


IMHO that would be the best thing.
But for non-console applications there is a special API call to enable the console.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy

www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 4 months 1 week ago #11815

  leon_ts's Avatar Topic Author leon_ts Offline Posts: 33
Robert,

On the one hand, using the System.Console class inside the VO.Console wrapper class will allow you to create pure .NET code for any platform. On the other hand, if I need pure .NET, I will just initially use the System.Console class in my code instead of VO.Console.

Given the above, as well as the fact that the VO.Console class is located in VOConsoleClasses.dll (a VO legacy for Win32), I would use the WriteFile() function in VO.Console.

Best regards,
Leonid

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 4 months 1 week ago #11816

  leon_ts's Avatar Topic Author leon_ts Offline Posts: 33
addition to my previous post:

VO.Console is very small class.
Therefore, rewriting it as a wrapper over System.Console class is also a good idea.

Please Log in or Create an account to join the conversation.

Last edit: by leon_ts.

Problem with class VO.Console 1 month 2 weeks ago #13271

  leon_ts's Avatar Topic Author leon_ts Offline Posts: 33
Hi, devteam

Is there any news to fix this error?

Best regards,
Leonid

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 1 month 1 week ago #13280

  robert's Avatar robert Offline Posts: 1540
Leonid,

leon_ts wrote: Hi, devteam

Is there any news to fix this error?

Best regards,
Leonid


I am sorry, but not yet.
I'll try to work on this later this week.

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 1 month 1 week ago #13338

  robert's Avatar robert Offline Posts: 1540
Leonid,

I have adjusted the VO Console classes to use System.Console internally.
You can find the new code here:
github.com/X-Sharp/XSharpPublic/tree/fea.../Console_Classes_SDK

Can you check if this does what you expect ?

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 1 month 1 week ago #13339

  leon_ts's Avatar Topic Author leon_ts Offline Posts: 33
Robert,
Many thanks!

A quick look at the code says this should work. But there is a problem with the TextAttribute property. In the current implementation it is incompatible with the VO version (Win32 parameters). In VO, the wNewAttr parameter represents the wAttributes parameter for the Win32 function SetConsoleTextAttribute(). Values are combinations that represent both the foreground color and the background color (defines FOREGROUND_ * + BACKGROUND_ *). I think the TextAttribute SET property in the updated class needs to be improved: select the colors from wNewAttr by mask and assign them through the System.ForegroundColor and System.BackgoundColor properties. Similar to GET.

Best regards,
Leonid

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 1 month 1 week ago #13340

  robert's Avatar robert Offline Posts: 1540
Leonid,

Do you want to contribute by writing this code for us ?

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 1 month 1 week ago #13341

  leon_ts's Avatar Topic Author leon_ts Offline Posts: 33
Robert,

Yes, I will be very glad to help. I will try to find the time either tonight or on the weekend (if this suits you).

Best regards,
Leonid

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 1 month 1 week ago #13347

  leon_ts's Avatar Topic Author leon_ts Offline Posts: 33
Robert,

Updates in the attachment.

Best regards,
Leonid
Attachments:

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 1 month 1 week ago #13349

  leon_ts's Avatar Topic Author leon_ts Offline Posts: 33
The code in the attachment implies that we do not know the values of the ConsoleColor enum and the numeric values of the attributes of the console text in win32. But if you make conditional assumptions, the code will be even simpler:
PROPERTY TextAttribute AS WORD
    GET
        RETURN (WORD)System.Console.ForegroundColor | (WORD)(System.Console.BackgroundColor) << 4
    END GET
    SET
        System.Console.ForegroundColor := (ConsoleColor) (WORD)(VALUE & 0x000F)
        System.Console.BackgroundColor := (ConsoleColor) (WORD)((VALUE >> 4) & 0x000F)
    END SET
END PROPERTY
and nothing changes in the constructor.

Best regards,
Leonid

Please Log in or Create an account to join the conversation.

Problem with class VO.Console 1 month 1 week ago #13351

  robert's Avatar robert Offline Posts: 1540
Leonid,

I think I like this one better.
I'll also add the FOREGROUND_ and BACKGROUND_ defines to the Console classes so no reference to Win32 is needed anymore.

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

  • Page:
  • 1