Foros del Web » Programación para mayores de 30 ;) » .NET »

Convertir este código de C# a otro del .net

Estas en el tema de Convertir este código de C# a otro del .net en el foro de .NET en Foros del Web. Hola: Tengo tres lenguajes con el código hecho. En C# C++ CLR y VB .net. Quiero adaptar este código en el cualquiera que entiendan la ...
  #1 (permalink)  
Antiguo 15/11/2017, 14:52
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 16 años, 10 meses
Puntos: 8
Convertir este código de C# a otro del .net

Hola:

Tengo tres lenguajes con el código hecho. En C# C++ CLR y VB .net. Quiero adaptar este código en el cualquiera que entiendan la gente al poco conocido lenguaje F#.

Los código se trata de abrir y cerrar la bandeja del lector de discos, sea IDE, SATA.

Código C#:
Código C++:
Ver original
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4.  
  5. namespace Lector_teclado_consola_cs
  6. {
  7.     class Program
  8.     {
  9.         [DllImport("winmm.dll")]
  10.         public static extern Int32 mciSendString(string lpstrCommand, StringBuilder lpstrReturnString,
  11.         int uReturnLength, IntPtr hwndCallback);
  12.  
  13.         public static StringBuilder rt = new StringBuilder(127);
  14.  
  15.         public static void DoEvents()
  16.         {
  17.             // Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
  18.             Console.SetCursorPosition(0, 6);
  19.             Console.Write("Abriendo...");
  20.         }
  21.  
  22.         public static void DoEvents2()
  23.         {
  24.             // Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
  25.             Console.SetCursorPosition(0, 6);
  26.             Console.Write("Cerrando...");
  27.         }
  28.  
  29.         static void Main(string[] args)
  30.         {
  31.             // Título de la ventana.
  32.             Console.Title = "Control lector de bandeja. C#";
  33.  
  34.             // Tamaño ventana consola.
  35.             Console.WindowWidth = 29; // X. Ancho.
  36.             Console.WindowHeight = 8; // Y. Alto.
  37.  
  38.             // Cursor invisible.
  39.             Console.CursorVisible = false;
  40.  
  41.             // Posición del mansaje en la ventana.
  42.             Console.SetCursorPosition(0, 0);
  43.             Console.Write(@"Control bandeja del lector:
  44.  
  45. A - Abrir bandeja.
  46. C - Cerrar bandeja.
  47. ===========================");
  48.  
  49.  
  50.  
  51.             ConsoleKey key;
  52.             //Console.CursorVisible = false;
  53.             do
  54.             {
  55.                 key = Console.ReadKey(true).Key;
  56.  
  57.                 string mensaje = string.Empty;
  58.  
  59.                 //Asignamos la tecla presionada por el usuario
  60.                 switch (key)
  61.                 {
  62.                     case ConsoleKey.A:
  63.                         // mensaje = "Abriendo...";
  64.                         Console.SetCursorPosition(0, 6);
  65.                         DoEvents();
  66.                         mciSendString("set CDAudio door open", rt, 127, IntPtr.Zero);
  67.                         mensaje = "Abierto.";
  68.                         break;
  69.  
  70.                     case ConsoleKey.C:
  71.                         // mensaje = "Cerrando...";
  72.                         Console.SetCursorPosition(0, 6);
  73.                         DoEvents2();
  74.                         mciSendString("set CDAudio door closed", rt, 127, IntPtr.Zero);
  75.                         mensaje = "Cerrado.";
  76.                         break;
  77.                 }
  78.  
  79.                 Console.SetCursorPosition(0, 6);
  80.                 Console.Write("           ");
  81.                 Console.SetCursorPosition(0, 6);
  82.                 Console.Write(mensaje);
  83.  
  84.             }
  85.             while (key != ConsoleKey.Escape);
  86.         }
  87.     }
  88. }

Código VB .net:
Código vb:
Ver original
  1. Imports System.Runtime.InteropServices
  2. Imports System.Text
  3.  
  4. Module Module1
  5.     <DllImport("winmm.dll")>
  6.     Public Function mciSendString(lpstrCommand As String, lpstrReturnString As StringBuilder, uReturnLength As Integer, hwndCallback As IntPtr) As Int32
  7.     End Function
  8.  
  9.     Public rt As New StringBuilder(127)
  10.  
  11.     Public Sub DoEvents()
  12.         ' Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
  13.        Console.SetCursorPosition(0, 6)
  14.         Console.Write("Abriendo...")
  15.     End Sub
  16.  
  17.     Public Sub DoEvents2()
  18.         ' Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
  19.        Console.SetCursorPosition(0, 6)
  20.         Console.Write("Cerrando...")
  21.     End Sub
  22.  
  23.     Sub Main()
  24.         ' Título de la ventana.
  25.        Console.Title = "Control lector de bandeja. Visual Basic"
  26.  
  27.         ' Tamaño ventana consola.
  28.        Console.WindowWidth = 29 ' X. Ancho.
  29.        Console.WindowHeight = 8 ' Y. Alto.
  30.        ' Cursor invisible.
  31.        Console.CursorVisible = False
  32.  
  33.         ' Posición del mansaje en la ventana.
  34.        Console.SetCursorPosition(0, 0)
  35.         Console.Write("Control bandeja del lector:" & vbCr & vbLf & vbCr & vbLf &
  36.                       "A - Abrir bandeja." & vbCr & vbLf &
  37.                       "C - Cerrar bandeja." & vbCr & vbLf &
  38.                       "===========================")
  39.  
  40.         Dim key As ConsoleKey
  41.         'Console.CursorVisible = false;
  42.        Do
  43.             key = Console.ReadKey(True).Key
  44.  
  45.             Dim mensaje As String = String.Empty
  46.  
  47.             'Asignamos la tecla presionada por el usuario
  48.            Select Case key
  49.                 Case ConsoleKey.A
  50.                     ' mensaje = "Abriendo...";
  51.                    Console.SetCursorPosition(0, 6)
  52.                     DoEvents()
  53.                     mciSendString("set CDAudio door open", rt, 127, IntPtr.Zero)
  54.                     mensaje = "Abierto."
  55.                     Exit Select
  56.  
  57.                 Case ConsoleKey.C
  58.                     ' mensaje = "Cerrando...";
  59.                    Console.SetCursorPosition(0, 6)
  60.                     DoEvents2()
  61.                     mciSendString("set CDAudio door closed", rt, 127, IntPtr.Zero)
  62.                     mensaje = "Cerrado."
  63.                     Exit Select
  64.             End Select
  65.  
  66.             Console.SetCursorPosition(0, 6)
  67.             Console.Write("           ")
  68.             Console.SetCursorPosition(0, 6)
  69.  
  70.             Console.Write(mensaje)
  71.         Loop While key <> ConsoleKey.Escape
  72.     End Sub
  73.  
  74. End Module

Código C++ CLR:
Código C++:
Ver original
  1. // Lector_teclado_consola_cpp.cpp: archivo de proyecto principal.
  2.  
  3. #include "stdafx.h"
  4.  
  5. using namespace System;
  6. using namespace System::Runtime::InteropServices;
  7. using namespace System::Text;
  8.  
  9. [DllImport("winmm.dll")]
  10. extern Int32 mciSendString(String^ lpstrCommand, StringBuilder^ lpstrReturnString,
  11.     int uReturnLength, IntPtr hwndCallback);
  12.  
  13. static void DoEvents()
  14. {
  15.     Console::SetCursorPosition(0, 6);
  16.     Console::Write("Abriendo...");
  17. }
  18.  
  19. static void DoEvents2()
  20. {
  21.     Console::SetCursorPosition(0, 6);
  22.     Console::Write("Cerrando...");
  23. }
  24.  
  25. int main(array<System::String ^> ^args)
  26. {
  27.     StringBuilder^ rt = gcnew StringBuilder(127);
  28.  
  29.     // Título de la ventana.
  30.     Console::Title = "Control lector de bandeja. C++ CLR";
  31.  
  32.     // Tamaño ventana consola.
  33.     Console::WindowWidth = 29; // X. Ancho.
  34.     Console::WindowHeight = 8; // Y. Alto.
  35.  
  36.                               // Cursor invisible.
  37.     Console::CursorVisible = false;
  38.  
  39.     // Posición del mansaje en la ventana.
  40.     Console::SetCursorPosition(0, 0);
  41.     Console::WriteLine("Control bandeja del lector : \n\n" +
  42.         "A - Abrir bandeja. \n" +
  43.         "C - Cerrar bandeja. \n" +
  44.         "========================== \n");
  45.     //Console::WriteLine("A - Abrir bandeja.");
  46.     //Console::WriteLine("C - Cerrar bandeja.");
  47.     //Console::Write("==========================");
  48.  
  49.     ConsoleKey key;
  50.     //Console::CursorVisible = false;
  51.     do
  52.     {
  53.         key = Console::ReadKey(true).Key;
  54.  
  55.         String^ mensaje = "";
  56.  
  57.         //Asignamos la tecla presionada por el usuario
  58.         switch (key)
  59.         {
  60.         case ConsoleKey::A:
  61.             mensaje = "Abriendo...";
  62.             Console::SetCursorPosition(0, 6);
  63.             DoEvents();
  64.             mciSendString("set CDAudio door open", rt, 127, IntPtr::Zero);
  65.             mensaje = "Abierto.";
  66.             break;
  67.  
  68.         case ConsoleKey::C:
  69.             mensaje = "Cerrando...";
  70.             Console::SetCursorPosition(0, 6);
  71.             DoEvents2();
  72.             mciSendString("set CDAudio door closed", rt, 127, IntPtr::Zero);
  73.             mensaje = "Cerrado.";
  74.             break;
  75.         }
  76.  
  77.         Console::SetCursorPosition(0, 6);
  78.         Console::Write("           ");
  79.         Console::SetCursorPosition(0, 6);
  80.         Console::Write(mensaje);
  81.  
  82.     } while (key != ConsoleKey::Escape);
  83.     return 0;
  84. }

¿Alguna posibilidad de adaptar el código a F#?

Saludos.
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar

Etiquetas: bandeja, net, ventana
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:10.