UWP: How to call WinAPI Method

假如想象 提交于 2021-02-10 05:45:47

问题


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'


回答1:


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"



来源:https://stackoverflow.com/questions/42444651/uwp-how-to-call-winapi-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!