1 | /* $Id: ClipboardStreamImpl-win.cpp 78725 2019-05-24 13:15:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * ClipboardStreamImpl-win.cpp - Shared Clipboard IStream object implementation (for CF_HDROP).
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
|
---|
23 | #include <VBox/GuestHost/SharedClipboard-win.h>
|
---|
24 |
|
---|
25 | #include <iprt/asm.h>
|
---|
26 | #include <iprt/ldr.h>
|
---|
27 | #include <iprt/thread.h>
|
---|
28 |
|
---|
29 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
30 | #include <VBox/GuestHost/SharedClipboard-win.h>
|
---|
31 | #include <strsafe.h>
|
---|
32 |
|
---|
33 | #include <VBox/log.h>
|
---|
34 |
|
---|
35 |
|
---|
36 | /*********************************************************************************************************************************
|
---|
37 | * Structures and Typedefs *
|
---|
38 | *********************************************************************************************************************************/
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 | /*********************************************************************************************************************************
|
---|
43 | * Static variables *
|
---|
44 | *********************************************************************************************************************************/
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 | VBoxClipboardWinStreamImpl::VBoxClipboardWinStreamImpl(SharedClipboardProvider *pProvider)
|
---|
49 | : m_lRefCount(1)
|
---|
50 | , m_pProvider(pProvider)
|
---|
51 | {
|
---|
52 | m_pProvider->AddRef();
|
---|
53 | }
|
---|
54 |
|
---|
55 | VBoxClipboardWinStreamImpl::~VBoxClipboardWinStreamImpl(void)
|
---|
56 | {
|
---|
57 | m_pProvider->Release();
|
---|
58 | }
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * IUnknown methods.
|
---|
62 | */
|
---|
63 |
|
---|
64 | STDMETHODIMP VBoxClipboardWinStreamImpl::QueryInterface(REFIID iid, void ** ppvObject)
|
---|
65 | {
|
---|
66 | AssertPtrReturn(ppvObject, E_INVALIDARG);
|
---|
67 |
|
---|
68 | if ( iid == IID_IStream
|
---|
69 | || iid == IID_IUnknown)
|
---|
70 | {
|
---|
71 | AddRef();
|
---|
72 | *ppvObject = this;
|
---|
73 | return S_OK;
|
---|
74 | }
|
---|
75 |
|
---|
76 | *ppvObject = 0;
|
---|
77 | return E_NOINTERFACE;
|
---|
78 | }
|
---|
79 |
|
---|
80 | STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::AddRef(void)
|
---|
81 | {
|
---|
82 | LONG lCount = InterlockedIncrement(&m_lRefCount);
|
---|
83 | LogFlowFunc(("lCount=%RI32\n", lCount));
|
---|
84 | return lCount;
|
---|
85 | }
|
---|
86 |
|
---|
87 | STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::Release(void)
|
---|
88 | {
|
---|
89 | LONG lCount = InterlockedDecrement(&m_lRefCount);
|
---|
90 | LogFlowFunc(("lCount=%RI32\n", m_lRefCount));
|
---|
91 | if (lCount == 0)
|
---|
92 | {
|
---|
93 | delete this;
|
---|
94 | return 0;
|
---|
95 | }
|
---|
96 |
|
---|
97 | return lCount;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * IStream methods.
|
---|
102 | */
|
---|
103 |
|
---|
104 | STDMETHODIMP VBoxClipboardWinStreamImpl::Clone(IStream** ppStream)
|
---|
105 | {
|
---|
106 | RT_NOREF(ppStream);
|
---|
107 |
|
---|
108 | LogFlowFuncEnter();
|
---|
109 | return E_NOTIMPL;
|
---|
110 | }
|
---|
111 |
|
---|
112 | STDMETHODIMP VBoxClipboardWinStreamImpl::Commit(DWORD dwFrags)
|
---|
113 | {
|
---|
114 | RT_NOREF(dwFrags);
|
---|
115 |
|
---|
116 | LogFlowFuncEnter();
|
---|
117 | return E_NOTIMPL;
|
---|
118 | }
|
---|
119 |
|
---|
120 | STDMETHODIMP VBoxClipboardWinStreamImpl::CopyTo(IStream* pDestStream, ULARGE_INTEGER nBytesToCopy, ULARGE_INTEGER* nBytesRead,
|
---|
121 | ULARGE_INTEGER* nBytesWritten)
|
---|
122 | {
|
---|
123 | RT_NOREF(pDestStream, nBytesToCopy, nBytesRead, nBytesWritten);
|
---|
124 |
|
---|
125 | LogFlowFuncEnter();
|
---|
126 | return E_NOTIMPL;
|
---|
127 | }
|
---|
128 |
|
---|
129 | STDMETHODIMP VBoxClipboardWinStreamImpl::LockRegion(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes,DWORD dwFlags)
|
---|
130 | {
|
---|
131 | RT_NOREF(nStart, nBytes, dwFlags);
|
---|
132 |
|
---|
133 | LogFlowFuncEnter();
|
---|
134 | return E_NOTIMPL;
|
---|
135 | }
|
---|
136 |
|
---|
137 | static ULONG cbFileSize = _1M;
|
---|
138 | static ULONG cbSizeRead = 0;
|
---|
139 |
|
---|
140 | STDMETHODIMP VBoxClipboardWinStreamImpl::Read(void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead)
|
---|
141 | {
|
---|
142 | /* If the file size is 0, already return at least 1 byte, else the whole operation will fail. */
|
---|
143 |
|
---|
144 | ULONG cbToRead = RT_MIN(cbFileSize - cbSizeRead, _4K /* nBytesToRead */);
|
---|
145 |
|
---|
146 | if (cbToRead > nBytesToRead)
|
---|
147 | cbToRead = nBytesToRead;
|
---|
148 |
|
---|
149 | LogFlowFunc(("pvBuffer=%p, nBytesToRead=%u -> cbSizeRead=%u, cbToRead=%u\n", pvBuffer, nBytesToRead, cbSizeRead, cbToRead));
|
---|
150 |
|
---|
151 | if (cbToRead)
|
---|
152 | {
|
---|
153 | memset(pvBuffer, cbToRead, 0x65);
|
---|
154 | cbSizeRead += cbToRead;
|
---|
155 | }
|
---|
156 |
|
---|
157 | if (nBytesRead)
|
---|
158 | *nBytesRead = cbToRead;
|
---|
159 |
|
---|
160 | if (cbSizeRead == cbFileSize)
|
---|
161 | cbSizeRead = 0;
|
---|
162 |
|
---|
163 | return S_OK;
|
---|
164 | }
|
---|
165 |
|
---|
166 | STDMETHODIMP VBoxClipboardWinStreamImpl::Revert(void)
|
---|
167 | {
|
---|
168 | LogFlowFuncEnter();
|
---|
169 | return E_NOTIMPL;
|
---|
170 | }
|
---|
171 |
|
---|
172 | STDMETHODIMP VBoxClipboardWinStreamImpl::Seek(LARGE_INTEGER nMove, DWORD dwOrigin, ULARGE_INTEGER* nNewPos)
|
---|
173 | {
|
---|
174 | RT_NOREF(nMove, dwOrigin, nNewPos);
|
---|
175 |
|
---|
176 | LogFlowFuncEnter();
|
---|
177 | return E_NOTIMPL;
|
---|
178 | }
|
---|
179 |
|
---|
180 | STDMETHODIMP VBoxClipboardWinStreamImpl::SetSize(ULARGE_INTEGER nNewSize)
|
---|
181 | {
|
---|
182 | RT_NOREF(nNewSize);
|
---|
183 |
|
---|
184 | LogFlowFuncEnter();
|
---|
185 | return E_NOTIMPL;
|
---|
186 | }
|
---|
187 |
|
---|
188 | STDMETHODIMP VBoxClipboardWinStreamImpl::Stat(STATSTG* statstg, DWORD dwFlags)
|
---|
189 | {
|
---|
190 | RT_NOREF(statstg, dwFlags);
|
---|
191 |
|
---|
192 | LogFlowFuncEnter();
|
---|
193 | return E_NOTIMPL;
|
---|
194 | }
|
---|
195 |
|
---|
196 | STDMETHODIMP VBoxClipboardWinStreamImpl::UnlockRegion(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes, DWORD dwFlags)
|
---|
197 | {
|
---|
198 | RT_NOREF(nStart, nBytes, dwFlags);
|
---|
199 |
|
---|
200 | LogFlowFuncEnter();
|
---|
201 | return E_NOTIMPL;
|
---|
202 | }
|
---|
203 |
|
---|
204 | STDMETHODIMP VBoxClipboardWinStreamImpl::Write(const void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead)
|
---|
205 | {
|
---|
206 | RT_NOREF(pvBuffer, nBytesToRead, nBytesRead);
|
---|
207 |
|
---|
208 | LogFlowFuncEnter();
|
---|
209 | return E_NOTIMPL;
|
---|
210 | }
|
---|
211 |
|
---|
212 | /*
|
---|
213 | * Own stuff.
|
---|
214 | */
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Factory to create our own IStream implementation.
|
---|
218 | *
|
---|
219 | * @returns HRESULT
|
---|
220 | * @param pProvider Pointer to Shared Clipboard provider to use.
|
---|
221 | * @param ppStream Where to return the created stream object on success.
|
---|
222 | */
|
---|
223 | /* static */
|
---|
224 | HRESULT VBoxClipboardWinStreamImpl::Create(SharedClipboardProvider *pProvider, IStream **ppStream)
|
---|
225 | {
|
---|
226 | VBoxClipboardWinStreamImpl *pStream = new VBoxClipboardWinStreamImpl(pProvider);
|
---|
227 | if (pStream)
|
---|
228 | {
|
---|
229 | pStream->AddRef();
|
---|
230 |
|
---|
231 | *ppStream = pStream;
|
---|
232 | return S_OK;
|
---|
233 | }
|
---|
234 |
|
---|
235 | return E_FAIL;
|
---|
236 | }
|
---|
237 |
|
---|