Ну, я пытаюсь перенести MessageBox с C++ на C# и постоянно получаю эту ошибку: CS1503 [аргумент 4] — не могу преобразовать из «MessageBoxButtons» — (это перечисление) в «ulong». Я уже устал менять тип с UInt64 для long и ulong
Вот я хотел это проверить:
using System;
using CSLib;
namespace CSDTCore
{
public class Core
{
public int install()
{
MessageBox msgbox = new MessageBox(IntPtr.Zero, "test text", "test title", MessageBox.MessageBoxButtons.MB_ABORTRETRYIGNORE);
msgbox.ShowMessageBox();
return 0;
}
}
}
Ну, я пытаюсь перенести MessageBox с C++ на C# и постоянно получаю эту ошибку: CS1503 [аргумент 4] — не могу преобразовать из «MessageBoxButtons» — (это перечисление) в «ulong». Я уже устал менять тип с UInt64 для long и ulong Вот я хотел это проверить: [code]using System; using CSLib;
namespace CSDTCore { public class Core { public int install() { MessageBox msgbox = new MessageBox(IntPtr.Zero, "test text", "test title", MessageBox.MessageBoxButtons.MB_ABORTRETRYIGNORE); msgbox.ShowMessageBox(); return 0; } } } [/code] исходный код: [code]using System; using System.IO; using System.Runtime.InteropServices;
namespace CSLib { public class MessageBox { // Enum for message box buttons public enum MessageBoxButtons : UInt64 { // Abort, Retry, Ignore buttons MB_ABORTRETRYIGNORE = 0x00000002L, // Cancel, Try Again, Continue buttons MB_CANCELTRYCONTINUE = 0x00000006L, // Help button MB_HELP = 0x00004000L, // OK button MB_OK = 0x00000000L, // OK, Cancel buttons MB_OKCANCEL = 0x00000001L, // Retry, Cancel buttons MB_RETRYCANCEL = 0x00000005L, // Yes, No buttons MB_YESNO = 0x00000004L, // Yes, No, Cancel buttons MB_YESNOCANCEL = 0x00000003L }
// Enum for default button public enum MessageBoxDefaultButton : UInt64 { // First button is default MB_DEFBUTTON1 = 0x00000000L, // Second button is default MB_DEFBUTTON2 = 0x00000100L, // Third button is default MB_DEFBUTTON3 = 0x00000200L, // Fourth button is default MB_DEFBUTTON4 = 0x00000300L }
// Import the MessageBox function from User32.dll [DllImport("User32.dll", SetLastError = true, EntryPoint = "MessageBox")] static private extern int MessageBoxImported(IntPtr hWnd, string lpText, string lpCaption, UInt64 uType);
// Private fields for the message box private IntPtr WINDOWHANDLE = IntPtr.Zero; private string TEXT; private string TITLE; private UInt64 BEHAVIOR; private int RETURNVALUE;
// Constructor for the message box public MessageBox(IntPtr WindowHandle = default, string Text = null, string Title = null, UInt64 Behavior = default) { WINDOWHANDLE = WindowHandle; TEXT = Text; TITLE = Title; BEHAVIOR = Behavior; }
// Show themessage box public int ShowMessageBox(IntPtr WindowHandle = default, string Text = null, string Title = null, UInt64 Behavior = MessageBox.MessageBoxButtons.MB_OK) { // Use the default values if not provided if (WindowHandle == default) { WindowHandle = WINDOWHANDLE; }
if (Text == null) { Text = TEXT; }
if (Title == null) { Title = TITLE; }
if (Behavior == default) { Behavior = BEHAVIOR; }
// Call the imported MessageBox function int Return = MessageBoxImported(WindowHandle, Text, Title, Behavior);
RETURNVALUE = Return;
return Return; }
// Get the button clicked public int GetClickedButton() { if (RETURNVALUE == 0) { throw new InvalidDataException("User not interacted yet"); }
else { return RETURNVALUE; } } } } [/code] я уже устал заменять "UInt64" на "long", но это не сработало