UWP: How to call WinAPI Method

2

My question is simple.
How can I call a WinAPI Method like emptyClipboard in an UWP app?

I included the 'Windows Desktop Extensions for the UWP'

The method is listed under Windows API Index / Data Exchange / Clipboard Reference / Clipboard Functions

I've tried the following (js):

Windows.emptyClipboard();
Windows.WinAPI.emptyClipboard();
Windows.ApplicationModel.emptyClipboard();
Windows.DataExchange.emptyClipboard();
Windows.DataExchange.Clipboard.emptyClipboard();

each of them giving me the following error (as expected):

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'emptyClipboard'

javascript
windows
winapi
methods
uwp
asked on Stack Overflow Feb 24, 2017 by jonhue • edited Feb 24, 2017 by jonhue

1 Answer

2

You cannot call WinAPI functions directly from a Universal Windows application. You have to find the equivalent function in the Windows Runtime (WinRT).

To clear the Clipboard, use the follwing code:

Windows.ApplicationModel.DataTransfer.Clipboard.clear();

When you edit your UWP application project and add a reference to "Windows Desktop Extensions for the UWP", you do not allow the app to call WinAPI functions directly, but you enable using a part of the Windows Runtime (WinRT) that only makes sense on desktop computers.

Here is a list of WinRT functionality that is only available when you reference "Windows Desktop Extensions for the UWP"

answered on Stack Overflow Feb 24, 2017 by NineBerry • edited Feb 24, 2017 by NineBerry

User contributions licensed under CC BY-SA 3.0