VirtualBox

source: vbox/trunk/src/VBox/GuestHost/SharedClipboard/ClipboardStreamImpl-win.cpp@ 78725

Last change on this file since 78725 was 78725, checked in by vboxsync, 6 years ago

Shared Clipboard/URI: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
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
48VBoxClipboardWinStreamImpl::VBoxClipboardWinStreamImpl(SharedClipboardProvider *pProvider)
49 : m_lRefCount(1)
50 , m_pProvider(pProvider)
51{
52 m_pProvider->AddRef();
53}
54
55VBoxClipboardWinStreamImpl::~VBoxClipboardWinStreamImpl(void)
56{
57 m_pProvider->Release();
58}
59
60/*
61 * IUnknown methods.
62 */
63
64STDMETHODIMP 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
80STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::AddRef(void)
81{
82 LONG lCount = InterlockedIncrement(&m_lRefCount);
83 LogFlowFunc(("lCount=%RI32\n", lCount));
84 return lCount;
85}
86
87STDMETHODIMP_(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
104STDMETHODIMP VBoxClipboardWinStreamImpl::Clone(IStream** ppStream)
105{
106 RT_NOREF(ppStream);
107
108 LogFlowFuncEnter();
109 return E_NOTIMPL;
110}
111
112STDMETHODIMP VBoxClipboardWinStreamImpl::Commit(DWORD dwFrags)
113{
114 RT_NOREF(dwFrags);
115
116 LogFlowFuncEnter();
117 return E_NOTIMPL;
118}
119
120STDMETHODIMP 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
129STDMETHODIMP 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
137static ULONG cbFileSize = _1M;
138static ULONG cbSizeRead = 0;
139
140STDMETHODIMP 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
166STDMETHODIMP VBoxClipboardWinStreamImpl::Revert(void)
167{
168 LogFlowFuncEnter();
169 return E_NOTIMPL;
170}
171
172STDMETHODIMP 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
180STDMETHODIMP VBoxClipboardWinStreamImpl::SetSize(ULARGE_INTEGER nNewSize)
181{
182 RT_NOREF(nNewSize);
183
184 LogFlowFuncEnter();
185 return E_NOTIMPL;
186}
187
188STDMETHODIMP VBoxClipboardWinStreamImpl::Stat(STATSTG* statstg, DWORD dwFlags)
189{
190 RT_NOREF(statstg, dwFlags);
191
192 LogFlowFuncEnter();
193 return E_NOTIMPL;
194}
195
196STDMETHODIMP 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
204STDMETHODIMP 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 */
224HRESULT 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
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette