1 | /* $Id: ClipboardStreamImpl-win.cpp 78809 2019-05-28 10:54:53Z 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 | LogFlowThisFuncEnter();
|
---|
53 |
|
---|
54 | m_pProvider->AddRef();
|
---|
55 |
|
---|
56 | cbFileSize = _64M;
|
---|
57 | cbSizeRead = 0;
|
---|
58 | }
|
---|
59 |
|
---|
60 | VBoxClipboardWinStreamImpl::~VBoxClipboardWinStreamImpl(void)
|
---|
61 | {
|
---|
62 | LogFlowThisFuncEnter();
|
---|
63 | m_pProvider->Release();
|
---|
64 | }
|
---|
65 |
|
---|
66 | /*
|
---|
67 | * IUnknown methods.
|
---|
68 | */
|
---|
69 |
|
---|
70 | STDMETHODIMP VBoxClipboardWinStreamImpl::QueryInterface(REFIID iid, void ** ppvObject)
|
---|
71 | {
|
---|
72 | AssertPtrReturn(ppvObject, E_INVALIDARG);
|
---|
73 |
|
---|
74 | if ( iid == IID_IStream
|
---|
75 | || iid == IID_IUnknown)
|
---|
76 | {
|
---|
77 | AddRef();
|
---|
78 | *ppvObject = this;
|
---|
79 | return S_OK;
|
---|
80 | }
|
---|
81 |
|
---|
82 | *ppvObject = 0;
|
---|
83 | return E_NOINTERFACE;
|
---|
84 | }
|
---|
85 |
|
---|
86 | STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::AddRef(void)
|
---|
87 | {
|
---|
88 | LONG lCount = InterlockedIncrement(&m_lRefCount);
|
---|
89 | LogFlowFunc(("lCount=%RI32\n", lCount));
|
---|
90 | return lCount;
|
---|
91 | }
|
---|
92 |
|
---|
93 | STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::Release(void)
|
---|
94 | {
|
---|
95 | LONG lCount = InterlockedDecrement(&m_lRefCount);
|
---|
96 | LogFlowFunc(("lCount=%RI32\n", m_lRefCount));
|
---|
97 | if (lCount == 0)
|
---|
98 | {
|
---|
99 | delete this;
|
---|
100 | return 0;
|
---|
101 | }
|
---|
102 |
|
---|
103 | return lCount;
|
---|
104 | }
|
---|
105 |
|
---|
106 | /*
|
---|
107 | * IStream methods.
|
---|
108 | */
|
---|
109 |
|
---|
110 | STDMETHODIMP VBoxClipboardWinStreamImpl::Clone(IStream** ppStream)
|
---|
111 | {
|
---|
112 | RT_NOREF(ppStream);
|
---|
113 |
|
---|
114 | LogFlowFuncEnter();
|
---|
115 | return E_NOTIMPL;
|
---|
116 | }
|
---|
117 |
|
---|
118 | STDMETHODIMP VBoxClipboardWinStreamImpl::Commit(DWORD dwFrags)
|
---|
119 | {
|
---|
120 | RT_NOREF(dwFrags);
|
---|
121 |
|
---|
122 | LogFlowThisFuncEnter();
|
---|
123 | return E_NOTIMPL;
|
---|
124 | }
|
---|
125 |
|
---|
126 | STDMETHODIMP VBoxClipboardWinStreamImpl::CopyTo(IStream* pDestStream, ULARGE_INTEGER nBytesToCopy, ULARGE_INTEGER* nBytesRead,
|
---|
127 | ULARGE_INTEGER* nBytesWritten)
|
---|
128 | {
|
---|
129 | RT_NOREF(pDestStream, nBytesToCopy, nBytesRead, nBytesWritten);
|
---|
130 |
|
---|
131 | LogFlowThisFuncEnter();
|
---|
132 | return E_NOTIMPL;
|
---|
133 | }
|
---|
134 |
|
---|
135 | STDMETHODIMP VBoxClipboardWinStreamImpl::LockRegion(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes,DWORD dwFlags)
|
---|
136 | {
|
---|
137 | RT_NOREF(nStart, nBytes, dwFlags);
|
---|
138 |
|
---|
139 | LogFlowThisFuncEnter();
|
---|
140 | return E_NOTIMPL;
|
---|
141 | }
|
---|
142 |
|
---|
143 | STDMETHODIMP VBoxClipboardWinStreamImpl::Read(void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead)
|
---|
144 | {
|
---|
145 | /* If the file size is 0, already return at least 1 byte, else the whole operation will fail. */
|
---|
146 |
|
---|
147 | size_t cbRead = 0;
|
---|
148 | int rc = m_pProvider->ReadData(pvBuffer, (size_t)nBytesToRead, &cbRead);
|
---|
149 | if (RT_SUCCESS(rc))
|
---|
150 | {
|
---|
151 | if (*nBytesRead)
|
---|
152 | *nBytesRead = (ULONG)cbRead;
|
---|
153 | }
|
---|
154 |
|
---|
155 | LogFlowThisFunc(("nBytesToRead=%u, nBytesRead=%zu\n", nBytesToRead, cbRead));
|
---|
156 | return S_OK;
|
---|
157 | }
|
---|
158 |
|
---|
159 | STDMETHODIMP VBoxClipboardWinStreamImpl::Revert(void)
|
---|
160 | {
|
---|
161 | LogFlowThisFuncEnter();
|
---|
162 | return E_NOTIMPL;
|
---|
163 | }
|
---|
164 |
|
---|
165 | STDMETHODIMP VBoxClipboardWinStreamImpl::Seek(LARGE_INTEGER nMove, DWORD dwOrigin, ULARGE_INTEGER* nNewPos)
|
---|
166 | {
|
---|
167 | RT_NOREF(nMove, dwOrigin, nNewPos);
|
---|
168 |
|
---|
169 | LogFlowThisFuncEnter();
|
---|
170 | return E_NOTIMPL;
|
---|
171 | }
|
---|
172 |
|
---|
173 | STDMETHODIMP VBoxClipboardWinStreamImpl::SetSize(ULARGE_INTEGER nNewSize)
|
---|
174 | {
|
---|
175 | RT_NOREF(nNewSize);
|
---|
176 |
|
---|
177 | LogFlowThisFuncEnter();
|
---|
178 | return E_NOTIMPL;
|
---|
179 | }
|
---|
180 |
|
---|
181 | STDMETHODIMP VBoxClipboardWinStreamImpl::Stat(STATSTG* statstg, DWORD dwFlags)
|
---|
182 | {
|
---|
183 | RT_NOREF(statstg, dwFlags);
|
---|
184 |
|
---|
185 | LogFlowThisFuncEnter();
|
---|
186 | return E_NOTIMPL;
|
---|
187 | }
|
---|
188 |
|
---|
189 | STDMETHODIMP VBoxClipboardWinStreamImpl::UnlockRegion(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes, DWORD dwFlags)
|
---|
190 | {
|
---|
191 | RT_NOREF(nStart, nBytes, dwFlags);
|
---|
192 |
|
---|
193 | LogFlowThisFuncEnter();
|
---|
194 | return E_NOTIMPL;
|
---|
195 | }
|
---|
196 |
|
---|
197 | STDMETHODIMP VBoxClipboardWinStreamImpl::Write(const void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead)
|
---|
198 | {
|
---|
199 | RT_NOREF(pvBuffer, nBytesToRead, nBytesRead);
|
---|
200 |
|
---|
201 | LogFlowThisFuncEnter();
|
---|
202 | return E_NOTIMPL;
|
---|
203 | }
|
---|
204 |
|
---|
205 | /*
|
---|
206 | * Own stuff.
|
---|
207 | */
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * Factory to create our own IStream implementation.
|
---|
211 | *
|
---|
212 | * @returns HRESULT
|
---|
213 | * @param pProvider Pointer to Shared Clipboard provider to use.
|
---|
214 | * @param ppStream Where to return the created stream object on success.
|
---|
215 | */
|
---|
216 | /* static */
|
---|
217 | HRESULT VBoxClipboardWinStreamImpl::Create(SharedClipboardProvider *pProvider, IStream **ppStream)
|
---|
218 | {
|
---|
219 | AssertPtrReturn(pProvider, E_POINTER);
|
---|
220 |
|
---|
221 | VBoxClipboardWinStreamImpl *pStream = new VBoxClipboardWinStreamImpl(pProvider);
|
---|
222 | if (pStream)
|
---|
223 | {
|
---|
224 | pStream->AddRef();
|
---|
225 |
|
---|
226 | *ppStream = pStream;
|
---|
227 | return S_OK;
|
---|
228 | }
|
---|
229 |
|
---|
230 | return E_FAIL;
|
---|
231 | }
|
---|
232 |
|
---|