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

Buscar errores

Estas en el tema de Buscar errores en el foro de .NET en Foros del Web. Hola a todos y a todas: He intentado hacer este código de C++ CLR 2017. Quiero adaptar este trozo de código de C# a C++ ...
  #1 (permalink)  
Antiguo 15/11/2017, 01:29
 
Fecha de Ingreso: mayo-2007
Ubicación: PIC-16F84A
Mensajes: 727
Antigüedad: 16 años, 10 meses
Puntos: 8
Buscar errores

Hola a todos y a todas:

He intentado hacer este código de C++ CLR 2017.

Quiero adaptar este trozo de código de C# a C++ CLR o CLI.
Código:
        [DllImport("winmm.dll")]
        public static extern Int32 mciSendString(string lpstrCommand, StringBuilder lpstrReturnString,
        int uReturnLength, IntPtr hwndCallback);

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

¿Alguna idea para solvertar este problema?

Un cordial saludos.
__________________
Meta Shell, VERSIÓN 1.2.2
Descargar

Etiquetas: errores, 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 20:03.