question

ansalc-1556 avatar image
0 Votes"
ansalc-1556 asked ·

DllImport to import Win32 functions

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

https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportattribute?view=netcore-3.1

seems to indicate that it is valid for UWP

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

windows-uwp
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Any updates for your issue? Please feel free to contact us if you still have problems.

0 Votes 0 · ·

I haven't heard from you for a while. Have you solved your issue?

0 Votes 0 · ·

1 Answer

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT answered ·

Hello,

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.



· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.