Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win, is_format_avail(13) fails after Ctrl + C #33

Open
fufesou opened this issue Mar 3, 2024 · 7 comments
Open

Win, is_format_avail(13) fails after Ctrl + C #33

fufesou opened this issue Mar 3, 2024 · 7 comments

Comments

@fufesou
Copy link

fufesou commented Mar 3, 2024

Hi, thanks for this great crate.

It's not a bug of this crate, but it's a related strange issue.

issue

Have you ever meet the issue that:

  1. OS, windows
  2. Run an application as a system process
  3. Ctrl + C
  4. is_format_avail(13)

is_format_avail(13) returns 0, but GetLastError() returns 0.

related

Hi, I've used this crate through arboard .

Someone is facing this problem. But I cannot find out why it happens.

rustdesk/rustdesk#6859 (comment)

rustdesk/rustdesk#6859 (comment)

The code in arboard is

https://github.com/fufesou/arboard/blob/aa0de068a9b1bccad764a67276007768111ec3aa/src/platform/windows.rs#L489

thanks

It seems this issue happens only on his one machine.

It may be related to his machine settings.

It would be great if anyone knows about this issue or can give a little hint.

@DoumanAsh
Copy link
Owner

abroad code seems to be correct as it acquire clipboard before checking format
So the only reason I can think of is that there is bug in MS API

Note that IsClipboardFormatAvailable returning false is actually no error, it is just lack of content on clipboard

I provide wrapper over enumeration API
https://docs.rs/clipboard-win/latest/clipboard_win/raw/struct.EnumFormats.html

But it seems you already tried and see clipboard format is available

So I would suspect windows bug first

Another thing to consider is that I would recommend to check for both CF_TEXT and CF_UNICODETEXT
The reason being is that I'm not sure which format was originally pasted, but if it is CF_TEXT Unicode shall be available, but only as synthesized format (hence it could be reason of bug in MS API)

Note that all clipboard APIs will have errno set as 0 when format is not available so you could technically go ahead and use size directly skipping format is available

@fufesou
Copy link
Author

fufesou commented Mar 4, 2024

Note that all clipboard APIs will have errno set as 0 when format is not available so you could technically go ahead and use size directly skipping format is available

I've tried, but it fails

https://github.com/fufesou/arboard/blob/59f66d91b30a268bb52329e5dc53a46c637d7c7f/src/platform/windows.rs#L489

1709515120814

rustdesk/rustdesk#6859 (comment)

I'll try to find out what error can be returned by GetLastError().

@DoumanAsh
Copy link
Owner

GetLastError will return 0 when there is no data available on clipboard

Note that while clipboard is global, it is tied to user session (but this should not be a problem if service is part of user session)

@DoumanAsh
Copy link
Owner

There is important note about service on MS docs:
https://learn.microsoft.com/en-us/dotnet/framework/windows-services/introduction-to-windows-service-applications

Windows Service applications run in a different window station than the interactive station of the logged-on user. A window station is a secure object that contains a Clipboard, a set of global atoms, and a group of desktop objects. Because the station of the Windows service is not an interactive station, dialog boxes raised from within a Windows service application will not be seen and may cause your program to stop responding. Similarly, error messages should be logged in the Windows event log rather than raised in the user interface.

The Windows service classes supported by the .NET Framework do not support interaction with interactive stations, that is, the logged-on user. The .NET Framework also does not include classes that represent stations and desktops. If your Windows service must interact with other stations, you will need to access the unmanaged Windows API. For more information, see the Windows SDK documentation.

The interaction of the Windows service with the user or other stations must be carefully designed to include scenarios such as there being no logged on user, or the user having an unexpected set of desktop objects. In some cases, it may be more appropriate to write a Windows application that runs under the control of the user.

@DoumanAsh
Copy link
Owner

DoumanAsh commented Mar 4, 2024

@fufesou I checked my windows laptop and looking at default clipboard service it is runs (log ons) as my user
If you have multiple users of the rustdesk (I would recommend to check how they have service configured in tab Log On of the service) to see if it is different or not

@fufesou
Copy link
Author

fufesou commented Mar 4, 2024

RustDesk service is log on as "Local System account" by default. It works fine on my machine.

Maybe this option doesn't affect.

@DoumanAsh
Copy link
Owner

Well it was wild guess, in any case I do not have believe it has anything to do with winapi itself but I'll keep this issue open until you'll find solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants