41117

windows - access clipboard from service in c++

Question:

I have a Windows service written in C++ that needs to access the clipboard and read data from/paste data to it. I'm considering only textual data.

From <a href="https://msdn.microsoft.com/en-us/library/ms649048(VS.85).aspx" rel="nofollow">MSDN</a>'s documentation, I can use OpenClipboard, EmptyClipboard and SetClipboardData to achieve what I want to.

I would have to pass NULL to OpenClipboard since I don't have any UI and hence no window handles. However, this would mean -

<blockquote>

If an application calls OpenClipboard with hwnd set to NULL, EmptyClipboard sets the clipboard owner to NULL; this causes SetClipboardData to fail.

</blockquote>

which would mean I can't set data on the clipboard.

What would be the correct way to get around this problem? Is it possible without using any windows?

Answer1:

You definitely CAN access the clipboard from a non-GUI application. Windows even included a command-line app (clip.exe) to do it.<br /> However, before you spend too much time working on this...... The clipboard isn't shared among users on the same system. Suppose you have two users logged in. You can't copy data from one session, switch users (from the lock screen) and paste that same data. So presumably, your service would act like another user session, and your app would only be able to see data that was copied earlier within that same instance of the service.

Recommend

  • Grails eager fetch doesn't retrieve all data
  • How to extract a number from a string [duplicate]
  • Google Calendar Api is not showing event list
  • Jquery resizable reposition handle after scroll
  • How to get a list with description of all dba packages
  • How to initialize context? [closed]
  • Is there a way to link a linux's thread TID and a pthread_t “thread ID”
  • How to override jQuery promise callback
  • Granting permissions to Azure Active Directory Web Application automatically
  • 'doc_del_count' bigger than 'doc_count' on CouchDB
  • Regex for nested values
  • EntLib Way to Bind “Null” Value to Parameter
  • VBA Excel, loop through variables
  • converter json to two dimensional array
  • In matplotlib, how do you change the fontsize of a single figure?
  • JSR-330 support in Picocontainer : @Inject … @Named(\"xxx)
  • Creating a DropDownList
  • Who propagate bugfixes across branches (corporate development)?
  • Django model inheritance, filtering models
  • Entity Framework Code First TPC Inheritance Self-Referencing Child Class
  • Alert pop up with LWUIT
  • Scrapy recursive link crawler
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • Change JButton Shape while respecting Look And Feel
  • C# - Serializing and deserializing static member
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • Is possible to count alias result on mysql
  • Sending data from AppleScript to FileMaker records
  • How do you troubleshoot character encoding problems?
  • jQuery tmpl and DataLink beta
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • How to include full .NET prerequisite for Wix Burn installer
  • AngularJs get employee from factory
  • Benchmarking RAM performance - UWP and C#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • LevelDB C iterator
  • Is it possible to post an object from jquery to bottle.py?
  • How can i traverse a binary tree from right to left in java?
  • Unable to use reactive element in my shiny app