DllImport to import Win32 functions

ansalc 436 Reputation points

Is it possible to use DLLImport to import the Win32 MessageBox function?

using System.Runtime.InteropServices;
[DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

The following


seems to indicate that it is valid for UWP

However, although it compiles in my UWP C# app, it does not run.

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Roy Li - MSFT 32,731 Reputation points Microsoft Vendor


    Welcome to Microsoft Q&A!

    Not all win32 functions are available in UWP apps. See Win32 and COM APIs for an overview of Win32 API available to UWP apps. In the Extension APIs for Windows 10 devices part, you could see that only a few functions come from user32.dll could be used in UWP apps and the MessageBox function is not listed.

    Thank you.

    1 person found this answer helpful.
    0 comments No comments