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#include "stdafx.h"
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Text;
[DllImport("winmm.dll")]
static Int32 mciSendString(String^ lpstrCommand, StringBuilder^ lpstrReturnString,
int^ uReturnLength, IntPtr^ hwndCallback);
static StringBuilder ^ rt = gcnew StringBuilder(127);
static void DoEvents()
{
Console::SetCursorPosition(0, 6);
Console::Write("Abriendo...");
}
static void DoEvents2()
{
Console::SetCursorPosition(0, 6);
Console::Write("Cerrando...");
}
int main(array<System::String ^> ^args)
{
// Título de la ventana.
Console::Title = "Control lector de bandeja. C++ CLR";
// Tamaño ventana consola.
Console::WindowWidth = 29; // X. Ancho.
Console::WindowHeight = 8; // Y. Alto.
// Cursor invisible.
Console::CursorVisible = false;
// Posición del mansaje en la ventana.
Console::SetCursorPosition(0, 0);
Console::WriteLine("Control bandeja del lector :");
Console::WriteLine("A - Abrir bandeja.");
Console::WriteLine("C - Cerrar bandeja.");
Console::WriteLine("==========================");
ConsoleKey key;
//Console.CursorVisible = false;
do
{
key = Console::ReadKey(true).Key;
String^ mensaje = "";
//Asignamos la tecla presionada por el usuario
switch (key)
{
case ConsoleKey::A:
mensaje = "Abriendo...";
Console::SetCursorPosition(0, 6);
DoEvents();
mciSendString("set CDAudio door open", rt, 127, IntPtr::Zero);
mensaje = "Abierto.";
break;
case ConsoleKey::C:
mensaje = "Cerrando...";
Console::SetCursorPosition(0, 6);
DoEvents2();
mciSendString("set CDAudio door closed", rt, 127, IntPtr::Zero);
mensaje = "Cerrado.";
break;
}
Console::SetCursorPosition(0, 6);
Console::Write(" ");
Console::SetCursorPosition(0, 6);
Console::Write(mensaje);
} while (key != ConsoleKey::Escape);
return 0;
}
¿Alguna idea para solvertar este problema?
Un cordial saludos.