ReactOS 0.4.15-dev-7931-gfd331f1
vfdshext.cpp
Go to the documentation of this file.
1/*
2 vfdshext.cpp
3
4 Virtual Floppy Drive for Windows
5 Driver control library
6 shell extension COM shell extension class
7
8 Copyright (c) 2003-2005 Ken Kato
9*/
10
11#define WIN32_LEAN_AND_MEAN
12#include <windows.h>
13#include <shellapi.h>
14#include <shlobj.h>
15
16#include "vfdtypes.h"
17#include "vfdapi.h"
18#include "vfdlib.h"
19
20// class header
21#include "vfdshext.h"
22
23//
24// Constructor
25//
27{
28 VFDTRACE(0, ("CVfdShExt::CVfdShExt()\n"));
29
30 m_cRefCnt = 0L;
32 m_nDevice = (ULONG)-1;
33 m_sTarget[0] = '\0';
35
37}
38
39//
40// Destructor
41//
43{
44 VFDTRACE(0, ("CVfdShExt::~CVfdShExt()\n"));
45
46 if (m_pDataObj) {
47 m_pDataObj->Release();
48 }
49
51}
52
53// IUnknown members
54
57 LPVOID *ppv)
58{
59 *ppv = NULL;
60
61 if (IsEqualIID(riid, IID_IShellExtInit) ||
63 VFDTRACE(0,
64 ("CVfdShExt::QueryInterface()==>IID_IShellExtInit\n"));
65
66 *ppv = (LPSHELLEXTINIT)this;
67 }
68 else if (IsEqualIID(riid, IID_IContextMenu)) {
69 VFDTRACE(0,
70 ("CVfdShExt::QueryInterface()==>IID_IContextMenu\n"));
71
72 *ppv = (LPCONTEXTMENU)this;
73 }
74 else if (IsEqualIID(riid, IID_IShellPropSheetExt)) {
75 VFDTRACE(0,
76 ("CVfdShExt::QueryInterface()==>IID_IShellPropSheetExt\n"));
77
78 *ppv = (LPSHELLPROPSHEETEXT)this;
79 }
80
81 if (*ppv) {
82 AddRef();
83
84 return NOERROR;
85 }
86
87 VFDTRACE(0,
88 ("CVfdShExt::QueryInterface()==>Unknown Interface!\n"));
89
90 return E_NOINTERFACE;
91}
92
94{
95 VFDTRACE(0, ("CVfdShExt::AddRef()\n"));
96
97 return ++m_cRefCnt;
98}
99
101{
102 VFDTRACE(0, ("CVfdShExt::Release()\n"));
103
104 if (--m_cRefCnt) {
105 return m_cRefCnt;
106 }
107
108#ifndef __REACTOS__
109 delete this;
110#endif
111
112 return 0L;
113}
114
115// IShellExtInit members
116
117//
118// Initialize
119// Called by the shell to initialize the shell extension object
120//
122 LPCITEMIDLIST pIDFolder,
123 LPDATAOBJECT pDataObj,
124 HKEY hRegKey)
125{
126 CHAR drive = '\0';
127
128 VFDTRACE(0, ("CVfdShExt::Initialize()\n"));
129
130 UNREFERENCED_PARAMETER(hRegKey);
131
132 // Initialize can be called more than once
133
134 if (m_pDataObj) {
135 m_pDataObj->Release();
137 }
138
139 m_nDevice = (ULONG)-1;
140 m_sTarget[0] = '\0';
141
142 // Get the folder name
143 if (SHGetPathFromIDList(pIDFolder, m_sTarget)) {
144
145 // act as a Drag-and-Drop Handler
146
147 VFDTRACE(0, ("Drag-Drop: %s\n", m_sTarget));
148
150 VFDTRACE(0, ("Not a VFD drive\n"));
151 return NOERROR;
152 }
153
154 drive = m_sTarget[0];
156 }
157 else {
158
159 // act as a context menu handler
160
161 VFDTRACE(0, ("Context menu:\n"));
163 }
164
165 // Extract the target object name
166
167 if (pDataObj) {
168
169 STGMEDIUM medium;
170 FORMATETC fmt = {
171 CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL
172 };
173
174 if (SUCCEEDED(pDataObj->GetData(&fmt, &medium))) {
175 if (DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, NULL, 0)) {
176
177 DragQueryFile((HDROP)medium.hGlobal,
178 0, m_sTarget, sizeof(m_sTarget));
179 }
180
181 ReleaseStgMedium(&medium);
182 }
183 }
184
185 VFDTRACE(0, ("Target %s\n", m_sTarget));
186
187 if (!drive) {
188 // Contect menu handler
189 // -- Data object is the target drive
190 drive = m_sTarget[0];
191 }
192
193 HANDLE hDevice = VfdOpenDevice(drive);
194
195 if (hDevice == INVALID_HANDLE_VALUE) {
196 VFDTRACE(0, ("Not a VFD drive\n"));
197 return NOERROR;
198 }
199
201
202 CloseHandle(hDevice);
203
204 if (ret != ERROR_SUCCESS) {
205 m_nDevice = (ULONG)-1;
206 return NOERROR;
207 }
208
209 VFDTRACE(0, ("VFD device %d\n", m_nDevice));
210 // Store the data object
211
212 m_pDataObj = pDataObj;
213 m_pDataObj->AddRef();
214
215 return NOERROR;
216}
217
218/*
219STDMETHODIMP CVfdShExt::GetInfoFlags(
220 DWORD *pdwFlags)
221{
222 VFDTRACE(0, ("CVfdShExt::GetInfoFlags\n"));
223 *pdwFlags = 0;
224 return NOERROR;
225}
226
227STDMETHODIMP CVfdShExt::GetInfoTip(
228 DWORD dwFlags,
229 LPWSTR *ppwszTip)
230{
231 VFDTRACE(0, ("CVfdShExt::GetInfoTip\n"));
232 *ppwszTip = NULL;
233 return NOERROR;
234}
235*/
#define CF_HDROP
Definition: constants.h:410
#define STDMETHODIMP
Definition: basetyps.h:43
#define STDMETHODIMP_(t)
Definition: basetyps.h:44
const GUID IID_IUnknown
~CVfdShExt()
Definition: vfdshext.cpp:42
STDMETHODIMP QueryInterface(REFIID, LPVOID *)
Definition: vfdshext.cpp:55
ULONG m_cRefCnt
Definition: vfdshext.h:24
STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID)
Definition: vfdshext.cpp:121
LPDATAOBJECT m_pDataObj
Definition: vfdshext.h:25
CHAR m_sTarget[MAX_PATH]
Definition: vfdshext.h:27
BOOL m_bDragDrop
Definition: vfdshext.h:28
ULONG m_nDevice
Definition: vfdshext.h:26
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
IContextMenu * LPCONTEXTMENU
Definition: shobjidl.idl:1668
IShellExtInit * LPSHELLEXTINIT
Definition: shobjidl.idl:1286
ULONG AddRef()
ULONG Release()
#define SUCCEEDED(hr)
Definition: intsafe.h:50
unsigned int UINT
Definition: ndis.h:50
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
interface IDataObject * LPDATAOBJECT
Definition: objfwd.h:21
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
#define DragQueryFile
Definition: shellapi.h:686
#define SHGetPathFromIDList
Definition: shlobj.h:237
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
Definition: dsound.c:943
uint32_t ULONG
Definition: typedefs.h:59
HANDLE WINAPI VfdOpenDevice(ULONG nTarget)
Definition: vfdctl.c:1215
DWORD WINAPI VfdGetDeviceNumber(HANDLE hDevice, PULONG pNumber)
Definition: vfdctl.c:2359
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
UINT g_cDllRefCnt
int ret
#define GetDriveType
Definition: winbase.h:3812
#define DRIVE_REMOVABLE
Definition: winbase.h:251
#define E_NOINTERFACE
Definition: winerror.h:2364
#define NOERROR
Definition: winerror.h:2354
char CHAR
Definition: xmlstorage.h:175