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
SetClipboardData to achieve what I want to.
I would have to pass
OpenClipboard since I don't have any UI and hence no window handles. However, this would mean -
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.