VirtualBox

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

Last change on this file since 78583 was 78474, checked in by vboxsync, 5 years ago

Shared Clipboard/URI: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/* $Id: ClipboardStreamImpl-win.cpp 78474 2019-05-13 07:44:15Z 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(void)
49 : m_lRefCount(1)
50{
51
52}
53
54VBoxClipboardWinStreamImpl::~VBoxClipboardWinStreamImpl(void)
55{
56}
57
58/*
59 * IUnknown methods.
60 */
61
62STDMETHODIMP VBoxClipboardWinStreamImpl::QueryInterface(REFIID iid, void ** ppvObject)
63{
64 AssertPtrReturn(ppvObject, E_INVALIDARG);
65
66 if ( iid == IID_IStream
67 || iid == IID_IUnknown)
68 {
69 AddRef();
70 *ppvObject = this;
71 return S_OK;
72 }
73
74 *ppvObject = 0;
75 return E_NOINTERFACE;
76}
77
78STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::AddRef(void)
79{
80 LONG lCount = InterlockedIncrement(&m_lRefCount);
81 LogFlowFunc(("lCount=%RI32\n", lCount));
82 return lCount;
83}
84
85STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::Release(void)
86{
87 LONG lCount = InterlockedDecrement(&m_lRefCount);
88 LogFlowFunc(("lCount=%RI32\n", m_lRefCount));
89 if (lCount == 0)
90 {
91 delete this;
92 return 0;
93 }
94
95 return lCount;
96}
97
98/*
99 * IStream methods.
100 */
101
102STDMETHODIMP VBoxClipboardWinStreamImpl::Clone(IStream** ppStream)
103{
104 RT_NOREF(ppStream);
105
106 LogFlowFuncEnter();
107 return E_NOTIMPL;
108}
109
110STDMETHODIMP VBoxClipboardWinStreamImpl::Commit(DWORD dwFrags)
111{
112 RT_NOREF(dwFrags);
113
114 LogFlowFuncEnter();
115 return E_NOTIMPL;
116}
117
118STDMETHODIMP VBoxClipboardWinStreamImpl::CopyTo(IStream* pDestStream, ULARGE_INTEGER nBytesToCopy, ULARGE_INTEGER* nBytesRead,
119 ULARGE_INTEGER* nBytesWritten)
120{
121 RT_NOREF(pDestStream, nBytesToCopy, nBytesRead, nBytesWritten);
122
123 LogFlowFuncEnter();
124 return E_NOTIMPL;
125}
126
127STDMETHODIMP VBoxClipboardWinStreamImpl::LockRegion(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes,DWORD dwFlags)
128{
129 RT_NOREF(nStart, nBytes, dwFlags);
130
131 LogFlowFuncEnter();
132 return E_NOTIMPL;
133}
134
135static ULONG cbFileSize = _1M;
136static ULONG cbSizeRead = 0;
137
138STDMETHODIMP VBoxClipboardWinStreamImpl::Read(void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead)
139{
140 /* If the file size is 0, already return at least 1 byte, else the whole operation will fail. */
141
142 ULONG cbToRead = RT_MIN(cbFileSize - cbSizeRead, _4K /* nBytesToRead */);
143
144 if (cbToRead > nBytesToRead)
145 cbToRead = nBytesToRead;
146
147 LogFlowFunc(("pvBuffer=%p, nBytesToRead=%u -> cbSizeRead=%u, cbToRead=%u\n", pvBuffer, nBytesToRead, cbSizeRead, cbToRead));
148
149 if (cbToRead)
150 {
151 memset(pvBuffer, cbToRead, 0x65);
152 cbSizeRead += cbToRead;
153 }
154
155 if (nBytesRead)
156 *nBytesRead = cbToRead;
157
158 if (cbSizeRead == cbFileSize)
159 cbSizeRead = 0;
160
161 return S_OK;
162}
163
164STDMETHODIMP VBoxClipboardWinStreamImpl::Revert(void)
165{
166 LogFlowFuncEnter();
167 return E_NOTIMPL;
168}
169
170STDMETHODIMP VBoxClipboardWinStreamImpl::Seek(LARGE_INTEGER nMove, DWORD dwOrigin, ULARGE_INTEGER* nNewPos)
171{
172 RT_NOREF(nMove, dwOrigin, nNewPos);
173
174 LogFlowFuncEnter();
175 return E_NOTIMPL;
176}
177
178STDMETHODIMP VBoxClipboardWinStreamImpl::SetSize(ULARGE_INTEGER nNewSize)
179{
180 RT_NOREF(nNewSize);
181
182 LogFlowFuncEnter();
183 return E_NOTIMPL;
184}
185
186STDMETHODIMP VBoxClipboardWinStreamImpl::Stat(STATSTG* statstg, DWORD dwFlags)
187{
188 RT_NOREF(statstg, dwFlags);
189
190 LogFlowFuncEnter();
191 return E_NOTIMPL;
192}
193
194STDMETHODIMP VBoxClipboardWinStreamImpl::UnlockRegion(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes, DWORD dwFlags)
195{
196 RT_NOREF(nStart, nBytes, dwFlags);
197
198 LogFlowFuncEnter();
199 return E_NOTIMPL;
200}
201
202STDMETHODIMP VBoxClipboardWinStreamImpl::Write(const void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead)
203{
204 RT_NOREF(pvBuffer, nBytesToRead, nBytesRead);
205
206 LogFlowFuncEnter();
207 return E_NOTIMPL;
208}
209
210/*
211 * Own stuff.
212 */
213
214/* static */
215HRESULT VBoxClipboardWinStreamImpl::Create(IStream **ppStream)
216{
217 VBoxClipboardWinStreamImpl *pStream = new VBoxClipboardWinStreamImpl();
218 if (pStream)
219 {
220 pStream->AddRef();
221
222 *ppStream = pStream;
223 return S_OK;
224 }
225
226 return E_FAIL;
227}
228
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use