ReactOS  0.4.13-dev-39-g8b6696f
vcdcontroltool.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Virtual CD Control Tool
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: modules/rosapps/applications/vcdcontroltool/vcdcontroltool.c
5  * PURPOSE: main dialog implementation
6  * COPYRIGHT: Copyright 2018 Pierre Schweitzer
7  *
8  */
9 
10 #define WIN32_NO_STATUS
11 #include <stdarg.h>
12 #include <windef.h>
13 #include <winbase.h>
14 #include <winuser.h>
15 #include <wingdi.h>
16 #include <winsvc.h>
17 #include <winreg.h>
18 #include <commctrl.h>
19 #include <commdlg.h>
20 #include <wchar.h>
21 #include <ndk/rtltypes.h>
22 #include <ndk/rtlfuncs.h>
23 
24 #include <vcdioctl.h>
25 #define IOCTL_CDROM_BASE FILE_DEVICE_CD_ROM
26 #define IOCTL_CDROM_EJECT_MEDIA CTL_CODE(IOCTL_CDROM_BASE, 0x0202, METHOD_BUFFERED, FILE_READ_ACCESS)
27 
28 #include "resource.h"
29 
34 /* FIXME: to improve, ugly hack */
36 
37 static
38 HANDLE
40 {
41  /* Just open the device */
42  return CreateFile(L"\\\\.\\\\VirtualCdRom", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
44 }
45 
46 static
47 HANDLE
49 {
50  WCHAR Device[255];
51 
52  /* Make name */
53  wsprintf(Device, L"\\\\.\\%c:", Letter);
54 
55  /* And open */
58 }
59 
60 static
61 VOID
63 {
65  WCHAR szFormat[50];
66  WCHAR szText[MAX_PATH + 50];
67  WCHAR szImage[MAX_PATH];
68  HANDLE hMaster, hLet;
69  DWORD BytesRead, i;
70  DRIVES_LIST Drives;
71  BOOLEAN Res;
73  LVITEMW lvItem;
74  LRESULT lResult;
75  INT iSelected;
76 
77  /* Get our list view */
79 
80  /* Purge it */
82 
83  /* Now, query the driver for all the devices */
84  hMaster = OpenMaster();
85  if (hMaster != INVALID_HANDLE_VALUE)
86  {
87  Res = DeviceIoControl(hMaster, IOCTL_VCDROM_ENUMERATE_DRIVES, NULL, 0, &Drives, sizeof(Drives), &BytesRead, NULL);
88  CloseHandle(hMaster);
89 
90  if (Res)
91  {
92  /* Loop to add all the devices to the list */
93  iSelected = -1;
94  for (i = 0; i < Drives.Count; ++i)
95  {
96  /* We'll query device one by one */
97  hLet = OpenLetter(Drives.Drives[i]);
98  if (hLet != INVALID_HANDLE_VALUE)
99  {
100  /* Get info about the mounted image */
102  if (Res)
103  {
104  /* First of all, add our driver letter to the list */
105  ZeroMemory(&lvItem, sizeof(LVITEMW));
106  lvItem.mask = LVIF_TEXT;
107  lvItem.pszText = szText;
108  lvItem.iItem = i;
109  szText[0] = Drives.Drives[i];
110  szText[1] = L':';
111  szText[2] = 0;
112 
113  /* If it worked, we'll complete with the info about the device:
114  * (mounted? which image?)
115  */
116  lResult = SendMessage(hListView, LVM_INSERTITEM, 0, (LPARAM)&lvItem);
117  if (lResult != -1)
118  {
119  /* If it matches arg, that's the letter to select at the end */
120  if (Drives.Drives[i] == Letter)
121  {
122  iSelected = lResult;
123  }
124 
125  /* We'll fill second column with info */
126  lvItem.iSubItem = 1;
127 
128  /* Gather the image path */
129  if (Image.Length != 0)
130  {
131  memcpy(szImage, Image.Path, Image.Length);
132  szImage[(Image.Length / sizeof(WCHAR))] = L'\0';
133  }
134 
135  /* It's not mounted... */
136  if (Image.Mounted == 0)
137  {
138  /* If we don't have an image, set default text instead */
139  if (Image.Length == 0)
140  {
141  szImage[0] = 0;
142  LoadString(hInstance, IDS_NONE, szImage, sizeof(szImage) / sizeof(WCHAR));
143  szImage[(sizeof(szImage) / sizeof(WCHAR)) - 1] = L'\0';
144  }
145 
146  /* Display the last known image */
147  szFormat[0] = 0;
148  LoadString(hInstance, IDS_NOMOUNTED, szFormat, sizeof(szFormat) / sizeof(WCHAR));
149  szFormat[(sizeof(szFormat) / sizeof(WCHAR)) - 1] = L'\0';
150 
151  swprintf(szText, szFormat, szImage);
152  lvItem.pszText = szText;
153  }
154  else
155  {
156  /* Mounted, just display the image path */
157  lvItem.pszText = szImage;
158  }
159 
160  /* Set text */
161  SendMessage(hListView, LVM_SETITEM, lResult, (LPARAM)&lvItem);
162  }
163  }
164 
165  /* Don't leak our device */
166  CloseHandle(hLet);
167  }
168  }
169 
170  /* If we had something to select, then just do it */
171  if (iSelected != -1)
172  {
173  ZeroMemory(&lvItem, sizeof(LVITEMW));
174 
175  lvItem.mask = LVIF_STATE;
176  lvItem.iItem = iSelected;
177  lvItem.state = LVIS_FOCUSED | LVIS_SELECTED;
179  SendMessage(hListView, LVM_SETITEMSTATE, iSelected, (LPARAM)&lvItem);
180  }
181  }
182  }
183 }
184 
185 VOID
187 {
188  HWND hControl;
189 
190  /* If started, disable start button */
192  EnableWindow(hControl, !Started);
193 
194  /* If started, enable stop button */
195  hControl = GetDlgItem(hDriverWnd, IDC_DRIVERSTOP);
196  EnableWindow(hControl, Started);
197 }
198 
199 INT_PTR
201 {
202  DWORD dwSize;
203  SC_HANDLE hMgr, hSvc;
204  LPQUERY_SERVICE_CONFIGW pConfig;
205  WCHAR szText[2 * MAX_PATH];
206  HWND hControl;
208 
209  hDriverWnd = hDlg;
210 
211  /* Open service manager */
213  if (hMgr != NULL)
214  {
215  /* Open our service */
216  hSvc = OpenService(hMgr, L"Vcdrom", SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS);
217  if (hSvc != NULL)
218  {
219  /* Probe its config size */
220  if (!QueryServiceConfig(hSvc, NULL, 0, &dwSize) &&
222  {
223  /* And get its config */
224  pConfig = HeapAlloc(GetProcessHeap(), 0, dwSize);
225 
226  if (QueryServiceConfig(hSvc, pConfig, dwSize, &dwSize))
227  {
228  /* Display name & driver */
229  wsprintf(szText, L"%s:\n(%s)", pConfig->lpDisplayName, pConfig->lpBinaryPathName);
230  hControl = GetDlgItem(hDriverWnd, IDC_DRIVERINFO);
231  SendMessage(hControl, WM_SETTEXT, 0, (LPARAM)szText);
232  }
233 
234  HeapFree(GetProcessHeap(), 0, pConfig);
235  }
236 
237  /* Get its status */
238  if (QueryServiceStatus(hSvc, &Status))
239  {
240  if (Status.dwCurrentState != SERVICE_RUNNING &&
241  Status.dwCurrentState != SERVICE_START_PENDING)
242  {
244  }
245  else
246  {
248  }
249  }
250 
251  CloseServiceHandle(hSvc);
252  }
253 
254  CloseServiceHandle(hMgr);
255  }
256 
257  /* FIXME: we don't allow uninstall/install */
258  {
260  EnableWindow(hControl, FALSE);
262  EnableWindow(hControl, FALSE);
263  }
264 
265  /* Display our sub window */
266  ShowWindow(hDlg, SW_SHOW);
267 
268  return TRUE;
269 }
270 
271 static
272 VOID
274 {
275  SC_HANDLE hMgr, hSvc;
276 
277  /* Open the SC manager */
279  if (hMgr != NULL)
280  {
281  /* Open the service matching our driver */
282  hSvc = OpenService(hMgr, L"Vcdrom", SERVICE_START);
283  if (hSvc != NULL)
284  {
285  /* Start it */
286  /* FIXME: improve */
287  StartService(hSvc, 0, NULL);
288 
289  CloseServiceHandle(hSvc);
290 
291  /* Refresh the list in case there were persistent mounts */
293 
294  /* Update buttons */
296  }
297 
298  CloseServiceHandle(hMgr);
299  }
300 }
301 
302 static
303 VOID
305 {
306  SC_HANDLE hMgr, hSvc;
308 
309  /* Open the SC manager */
311  if (hMgr != NULL)
312  {
313  /* Open the service matching our driver */
314  hSvc = OpenService(hMgr, L"Vcdrom", SERVICE_STOP);
315  if (hSvc != NULL)
316  {
317  /* Stop it */
318  /* FIXME: improve */
320 
321  CloseServiceHandle(hSvc);
322 
323  /* Refresh the list to clear it */
325 
326  /* Update buttons */
328  }
329 
330  CloseServiceHandle(hMgr);
331  }
332 }
333 
334 static
335 INT_PTR
337  LPARAM lParam)
338 {
339  WORD Msg;
340 
341  /* Dispatch the message for the controls we manage */
342  Msg = LOWORD(wParam);
343  switch (Msg)
344  {
345  case IDC_DRIVEROK:
347  return TRUE;
348 
349  case IDC_DRIVERSTART:
350  StartDriver();
351  return TRUE;
352 
353  case IDC_DRIVERSTOP:
354  StopDriver();
355  return TRUE;
356  }
357 
358  return FALSE;
359 }
360 
361 static
362 INT_PTR
363 CALLBACK
365  UINT Message,
366  WPARAM wParam,
367  LPARAM lParam)
368 {
369  /* Dispatch the message */
370  switch (Message)
371  {
372  case WM_INITDIALOG:
373  return QueryDriverInfo(hDlg);
374 
375  case WM_COMMAND:
377 
378  case WM_CLOSE:
379  return DestroyWindow(hDlg);
380  }
381 
382  return FALSE;
383 }
384 
385 static
386 VOID
388 {
389  /* Just create a new window with our driver control dialog */
392  NULL,
394  0);
395 }
396 
397 static
398 INT_PTR
400  LPARAM lParam)
401 {
402  HWND hEditText;
403 
404  hMountWnd = hDlg;
405 
406  /* Set the file name that was passed when creating dialog */
407  hEditText = GetDlgItem(hMountWnd, IDC_MOUNTIMAGE);
408  SendMessage(hEditText, WM_SETTEXT, 0, lParam);
409 
410  /* Show our window */
411  ShowWindow(hDlg, SW_SHOW);
412 
413  return TRUE;
414 }
415 
417 DWORD
419 {
420  return (a > b ? b : a);
421 }
422 
423 static
424 VOID
426 {
427  HWND hControl;
428  WCHAR szFileName[MAX_PATH];
429  MOUNT_PARAMETERS MountParams;
430  UNICODE_STRING NtPathName;
431  HANDLE hLet;
433  BOOLEAN bPersist, Res;
434  WCHAR szKeyName[256];
435  HKEY hKey;
436 
437  /* Zero our input structure */
438  ZeroMemory(&MountParams, sizeof(MOUNT_PARAMETERS));
439 
440  /* Do we have to suppress UDF? */
441  hControl = GetDlgItem(hMountWnd, IDC_MOUNTUDF);
442  if (SendMessage(hControl, BM_GETCHECK, 0, 0) == BST_CHECKED)
443  {
444  MountParams.Flags |= MOUNT_FLAG_SUPP_UDF;
445  }
446 
447  /* Do we have to suppress Joliet? */
448  hControl = GetDlgItem(hMountWnd, IDC_MOUNTJOLIET);
449  if (SendMessage(hControl, BM_GETCHECK, 0, 0) == BST_CHECKED)
450  {
451  MountParams.Flags |= MOUNT_FLAG_SUPP_JOLIET;
452  }
453 
454  /* Should the mount be persistent? */
456  bPersist = (SendMessage(hControl, BM_GETCHECK, 0, 0) == BST_CHECKED);
457 
458  /* Get the file name */
459  hControl = GetDlgItem(hMountWnd, IDC_MOUNTIMAGE);
460  GetWindowText(hControl, szFileName, sizeof(szFileName) / sizeof(WCHAR));
461 
462  /* Get NT path for the driver */
463  if (RtlDosPathNameToNtPathName_U(szFileName, &NtPathName, NULL, NULL))
464  {
465  /* Copy it in the parameter structure */
466  wcsncpy(MountParams.Path, NtPathName.Buffer, 255);
467  MountParams.Length = Min(NtPathName.Length, 255 * sizeof(WCHAR));
468  RtlFreeHeap(RtlGetProcessHeap(), 0, NtPathName.Buffer);
469 
470  /* Open the device */
471  hLet = OpenLetter(wMountLetter);
472  if (hLet != INVALID_HANDLE_VALUE)
473  {
474  /* And issue the mount IOCTL */
475  Res = DeviceIoControl(hLet, IOCTL_VCDROM_MOUNT_IMAGE, &MountParams, sizeof(MountParams), NULL, 0, &BytesRead, NULL);
476 
477  CloseHandle(hLet);
478 
479  /* Refresh the list so that our mount appears */
481 
482  /* If mount succeed and has to persistent, write it to registry */
483  if (Res && bPersist)
484  {
485  wsprintf(szKeyName, L"SYSTEM\\CurrentControlSet\\Services\\Vcdrom\\Parameters\\Device%c", wMountLetter);
487  {
488  wcsncpy(szKeyName, MountParams.Path, MountParams.Length);
489  szKeyName[MountParams.Length / sizeof(WCHAR)] = 0;
490  RegSetValueExW(hKey, L"IMAGE", 0, REG_SZ, (BYTE *)szKeyName, MountParams.Length);
491 
492  szKeyName[0] = wMountLetter;
493  szKeyName[1] = L':';
494  szKeyName[2] = 0;
495  RegSetValueExW(hKey, L"DRIVE", 0, REG_SZ, (BYTE *)szKeyName, 3 * sizeof(WCHAR));
496 
497  RegCloseKey(hKey);
498  }
499  }
500  }
501  }
502 
504 }
505 
506 static
507 INT_PTR
509  LPARAM lParam)
510 {
511  WORD Msg;
512 
513  /* Dispatch the message for the controls we manage */
514  Msg = LOWORD(wParam);
515  switch (Msg)
516  {
517  case IDC_MOUNTCANCEL:
519  return TRUE;
520 
521  case IDC_MOUNTOK:
522  PerformMount();
523  return TRUE;
524  }
525 
526  return FALSE;
527 }
528 
529 static
530 INT_PTR
531 CALLBACK
533  UINT Message,
534  WPARAM wParam,
535  LPARAM lParam)
536 {
537  /* Dispatch the message */
538  switch (Message)
539  {
540  case WM_INITDIALOG:
541  return SetMountFileName(hDlg, lParam);
542 
543  case WM_COMMAND:
545 
546  case WM_CLOSE:
547  return DestroyWindow(hDlg);
548  }
549 
550  return FALSE;
551 }
552 
553 static
554 VOID
556 {
557  WCHAR Letter;
558  BOOLEAN Res;
560  HANDLE hMaster;
561 
562  /* Open the driver */
563  hMaster = OpenMaster();
564  if (hMaster != INVALID_HANDLE_VALUE)
565  {
566  /* Issue the create IOCTL */
567  Res = DeviceIoControl(hMaster, IOCTL_VCDROM_CREATE_DRIVE, NULL, 0, &Letter, sizeof(WCHAR), &BytesRead, NULL);
568  CloseHandle(hMaster);
569 
570  /* If it failed, reset the drive letter */
571  if (!Res)
572  {
573  Letter = 0;
574  }
575 
576  /* Refresh devices list. If it succeed, we pass the created drive letter
577  * So that, user can directly click on "mount" to mount an image, without
578  * needing to select appropriate device.
579  */
581  }
582 }
583 
584 static
585 WCHAR
587 {
588  INT iItem;
589  HWND hListView;
590  LVITEM lvItem;
591  WCHAR szText[255];
592 
593  /* Get the select device in the list view */
596  /* If there's one... */
597  if (iItem != -1)
598  {
599  ZeroMemory(&lvItem, sizeof(LVITEM));
600  lvItem.pszText = szText;
601  lvItem.cchTextMax = sizeof(szText) / sizeof(WCHAR);
602  szText[0] = 0;
603 
604  /* Get the item text, it will be the drive letter */
605  SendMessage(hListView, LVM_GETITEMTEXT, iItem, (LPARAM)&lvItem);
606  return szText[0];
607  }
608 
609  /* Nothing selected */
610  return 0;
611 }
612 
613 static
614 VOID
616 {
617  WCHAR szFilter[255];
618  WCHAR szFileName[MAX_PATH];
619  OPENFILENAMEW ImageOpen;
620 
621  /* Get the selected drive letter
622  * FIXME: I make it global, because I don't know how to pass
623  * it properly to the later involved functions.
624  * Feel free to improve (without breaking ;-))
625  */
627  /* We can only mount if we have a device */
628  if (wMountLetter != 0)
629  {
630  /* First of all, we need an image to mount */
631  ZeroMemory(&ImageOpen, sizeof(OPENFILENAMEW));
632 
633  ImageOpen.lStructSize = sizeof(ImageOpen);
634  ImageOpen.hwndOwner = NULL;
635  ImageOpen.lpstrFilter = szFilter;
636  ImageOpen.lpstrFile = szFileName;
637  ImageOpen.nMaxFile = MAX_PATH;
639 
640  /* Get our filter (only supported images) */
641  szFileName[0] = 0;
642  szFilter[0] = 0;
643  LoadString(hInstance, IDS_FILTER, szFilter, sizeof(szFilter) / sizeof(WCHAR));
644  szFilter[(sizeof(szFilter) / sizeof(WCHAR)) - 1] = L'\0';
645 
646  /* Get the image name */
647  if (!GetOpenFileName(&ImageOpen))
648  {
649  /* The user canceled... */
650  return;
651  }
652 
653  /* Start the mount dialog, so that user can select mount options */
656  NULL,
658  (LPARAM)szFileName);
659  }
660 }
661 
662 static
663 VOID
665 {
666  WCHAR Letter;
667  HANDLE hLet;
669 
670  /* Get the select drive letter */
672  if (Letter != 0)
673  {
674  /* Open it */
675  hLet = OpenLetter(Letter);
676  if (hLet != INVALID_HANDLE_VALUE)
677  {
678  /* And ask the driver for a remount */
680 
681  CloseHandle(hLet);
682 
683  /* Refresh the list, to display the fact the image is now mounted.
684  * Make sure it's selected as it was previously selected.
685  */
687  }
688  }
689 }
690 
691 static
692 VOID
694 {
695  WCHAR Letter;
696  HANDLE hLet;
698 
699  /* Get the select drive letter */
701  if (Letter != 0)
702  {
703  /* Open it */
704  hLet = OpenLetter(Letter);
705  if (hLet != INVALID_HANDLE_VALUE)
706  {
707  /* And ask the driver for an ejection */
709 
710  CloseHandle(hLet);
711 
712  /* Refresh the list, to display the fact the image is now unmounted but
713  * still known by the driver
714  * Make sure it's selected as it was previously selected.
715  */
717  }
718  }
719 }
720 
721 static
722 VOID
724 {
725  WCHAR Letter;
726  HANDLE hLet;
728 
729  /* Get the select drive letter */
731  if (Letter != 0)
732  {
733  /* Open it */
734  hLet = OpenLetter(Letter);
735  if (hLet != INVALID_HANDLE_VALUE)
736  {
737  /* And ask the driver for a deletion */
739 
740  CloseHandle(hLet);
741 
742  /* Refresh the list, to make the device disappear */
744  }
745  }
746 }
747 
748 static
749 INT_PTR
751  LPARAM lParam)
752 {
753  WORD Msg;
754 
755  /* Dispatch the message for the controls we manage */
756  Msg = LOWORD(wParam);
757  switch (Msg)
758  {
759  case IDC_MAINCONTROL:
760  DriverControl();
761  return TRUE;
762 
763  case IDC_MAINOK:
765  return TRUE;
766 
767  case IDC_MAINADD:
768  AddDrive();
769  return TRUE;
770 
771  case IDC_MAINMOUNT:
772  MountImage();
773  return TRUE;
774 
775  case IDC_MAINREMOUNT:
776  RemountImage();
777  return TRUE;
778 
779  case IDC_MAINEJECT:
780  EjectDrive();
781  return TRUE;
782 
783  case IDC_MAINREMOVE:
784  RemoveDrive();
785  return TRUE;
786  }
787 
788  return FALSE;
789 }
790 
791 static
793 {
794  HWND hEditText;
795  static const WCHAR szText[] = { L'0', 0 };
796 
797  /* Simply set '0' in all the edittext controls we
798  * manage regarding statistics.
799  */
800  hEditText = GetDlgItem(hWnd, IDC_MAINSECTORS);
801  SendMessage(hEditText, WM_SETTEXT, 0, (LPARAM)szText);
802 
803  hEditText = GetDlgItem(hWnd, IDC_MAINSIZE);
804  SendMessage(hEditText, WM_SETTEXT, 0, (LPARAM)szText);
805 
806  hEditText = GetDlgItem(hWnd, IDC_MAINFREE);
807  SendMessage(hEditText, WM_SETTEXT, 0, (LPARAM)szText);
808 
809  hEditText = GetDlgItem(hWnd, IDC_MAINTOTAL);
810  SendMessage(hEditText, WM_SETTEXT, 0, (LPARAM)szText);
811 }
812 
813 static
814 INT_PTR
816 {
817  WCHAR Letter;
818  LPNMHDR NmHdr;
819  WCHAR szText[255];
820  HWND hEditText;
821  DWORD ClusterSector, SectorSize, FreeClusters, Clusters, Sectors;
822 
823  NmHdr = (LPNMHDR)lParam;
824 
825  /* We only want notifications on click on our devices list */
826  if (NmHdr->code == NM_CLICK &&
827  NmHdr->idFrom == IDC_MAINDEVICES)
828  {
829  /* Get the newly selected device */
831  if (Letter != 0)
832  {
833  /* Setup its name */
834  szText[0] = Letter;
835  szText[1] = L':';
836  szText[2] = 0;
837 
838  /* And get its capacities */
839  if (GetDiskFreeSpace(szText, &ClusterSector, &SectorSize, &FreeClusters, &Clusters))
840  {
841  /* Nota: the application returns the total amount of clusters and sectors
842  * So, compute it
843  */
844  Sectors = ClusterSector * Clusters;
845 
846  /* And now, update statistics about the device */
847  hEditText = GetDlgItem(hWnd, IDC_MAINSECTORS);
848  wsprintf(szText, L"%ld", Sectors);
849  SendMessage(hEditText, WM_SETTEXT, 0, (LPARAM)szText);
850 
851  hEditText = GetDlgItem(hWnd, IDC_MAINSIZE);
852  wsprintf(szText, L"%ld", SectorSize);
853  SendMessage(hEditText, WM_SETTEXT, 0, (LPARAM)szText);
854 
855  hEditText = GetDlgItem(hWnd, IDC_MAINFREE);
856  wsprintf(szText, L"%ld", FreeClusters);
857  SendMessage(hEditText, WM_SETTEXT, 0, (LPARAM)szText);
858 
859  hEditText = GetDlgItem(hWnd, IDC_MAINTOTAL);
860  wsprintf(szText, L"%ld", Clusters);
861  SendMessage(hEditText, WM_SETTEXT, 0, (LPARAM)szText);
862 
863  return TRUE;
864  }
865  }
866 
867  /* We failed somewhere, make sure we're at 0 */
868  ResetStats();
869 
870  return TRUE;
871  }
872 
873  return FALSE;
874 }
875 
876 static
877 INT_PTR
879 {
880  WCHAR szText[255];
881  LVCOLUMNW lvColumn;
882  HWND hListView;
883 
884  hWnd = hDlg;
886 
887  /* Select the whole line, not just the first column */
889 
890  /* Set up the first column */
891  ZeroMemory(&lvColumn, sizeof(LVCOLUMNW));
892  lvColumn.pszText = szText;
893  lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
894  lvColumn.fmt = LVCFMT_LEFT;
895  lvColumn.cx = 100;
896  szText[0] = 0;
897  LoadString(hInstance, IDS_DRIVE, szText, sizeof(szText) / sizeof(WCHAR));
898  szText[(sizeof(szText) / sizeof(WCHAR)) - 1] = L'\0';
900 
901  /* Set up the second column */
902  szText[0] = 0;
903  lvColumn.cx = 350;
904  LoadString(hInstance, IDS_MAPPEDIMAGE, szText, sizeof(szText) / sizeof(WCHAR));
905  szText[(sizeof(szText) / sizeof(WCHAR)) - 1] = L'\0';
907 
908  /* Make sure stats are at 0 */
909  ResetStats();
910 
911  /* And populate our device list */
913 
914  return TRUE;
915 }
916 
917 static
918 INT_PTR
919 CALLBACK
921  UINT Message,
922  WPARAM wParam,
923  LPARAM lParam)
924 {
925  /* Dispatch the message */
926  switch (Message)
927  {
928  case WM_INITDIALOG:
929  return CreateListViewColumns(hDlg);
930 
931  case WM_COMMAND:
932  return HandleCommand(wParam, lParam);
933 
934  case WM_NOTIFY:
935  return HandleNotify(lParam);
936 
937  case WM_CLOSE:
938  return DestroyWindow(hDlg);
939 
940  case WM_DESTROY:
941  PostQuitMessage(0);
942  return TRUE;
943  }
944 
945  return FALSE;
946 }
947 
948 INT
949 WINAPI
951  HINSTANCE hPrev,
952  LPWSTR Cmd,
953  int iCmd)
954 {
955  MSG Msg;
956 
957  hInstance = hInst;
958 
959  /* Just start our main window */
962  NULL,
964  0);
965  /* And dispatch messages in case of a success */
966  if (hWnd != NULL)
967  {
968  while (GetMessageW(&Msg, NULL, 0, 0) != 0)
969  {
972  }
973  }
974 
975  return 0;
976 }
#define StartService
Definition: winsvc.h:585
#define IDC_MOUNTCANCEL
Definition: resource.h:21
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
#define OFN_EXPLORER
Definition: commdlg.h:104
#define MOUNT_FLAG_SUPP_UDF
Definition: vcdioctl.h:15
#define IOCTL_CDROM_EJECT_MEDIA
static INT_PTR CALLBACK MountDialogProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
#define IDS_NOMOUNTED
Definition: resource.h:35
#define MAKEINTRESOURCE
Definition: winuser.h:591
DWORD Flags
Definition: commdlg.h:373
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
LPCWSTR lpstrFilter
Definition: commdlg.h:363
#define IDS_FILTER
Definition: resource.h:37
#define LVCF_WIDTH
Definition: commctrl.h:2559
#define ERROR_SUCCESS
Definition: deptool.c:10
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define LVCF_TEXT
Definition: commctrl.h:2560
static INT_PTR HandleMountCommand(WPARAM wParam, LPARAM lParam)
#define IDC_MAINREMOVE
Definition: resource.h:15
#define IDC_MAINMOUNT
Definition: resource.h:16
NTSTATUS FreeClusters(PNTFS_VCB Vcb, PNTFS_ATTR_CONTEXT AttrContext, ULONG AttrOffset, PFILE_RECORD_HEADER FileRecord, ULONG ClustersToFree)
Definition: attrib.c:1057
static INT_PTR HandleNotify(LPARAM lParam)
static INT_PTR CreateListViewColumns(HWND hDlg)
INT WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR Cmd, int iCmd)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define IDS_NONE
Definition: resource.h:122
#define QueryServiceConfig
Definition: winsvc.h:580
LPWSTR lpstrFile
Definition: commdlg.h:367
#define IDC_DRIVERSTART
Definition: resource.h:28
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
#define LVM_GETITEMTEXT
Definition: commctrl.h:2654
#define CALLBACK
Definition: compat.h:27
HWND hDriverWnd
#define LVS_EX_FULLROWSELECT
Definition: commctrl.h:2706
static PWSTR Image
Definition: pageheap.c:13
#define LVCFMT_LEFT
Definition: commctrl.h:2570
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
HINSTANCE hInstance
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define GetDiskFreeSpace
Definition: winbase.h:3621
#define IDC_MAINREMOUNT
Definition: resource.h:18
struct @1567 Msg[]
static VOID StopDriver(VOID)
VOID SetServiceState(BOOLEAN Started)
#define LVNI_SELECTED
Definition: commctrl.h:2396
UINT_PTR WPARAM
Definition: windef.h:207
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
int32_t INT_PTR
Definition: typedefs.h:62
#define IOCTL_VCDROM_MOUNT_IMAGE
Definition: vcdioctl.h:4
#define IDC_MOUNTOK
Definition: resource.h:20
static VOID StartDriver(VOID)
BOOL WINAPI DestroyWindow(_In_ HWND)
int32_t INT
Definition: typedefs.h:56
#define GetOpenFileName
Definition: commdlg.h:665
#define OpenService
Definition: winsvc.h:576
WPARAM wParam
Definition: combotst.c:138
UINT stateMask
Definition: commctrl.h:2336
struct tagNMHDR * LPNMHDR
#define FILE_SHARE_READ
Definition: compat.h:125
static INT_PTR SetMountFileName(HWND hDlg, LPARAM lParam)
DWORD lStructSize
Definition: commdlg.h:360
static VOID RemoveDrive(VOID)
#define IDC_DRIVEROK
Definition: resource.h:26
#define GetWindowText
Definition: winuser.h:5664
static HANDLE OpenMaster(VOID)
static HANDLE OpenLetter(WCHAR Letter)
#define IDC_DRIVERINFO
Definition: resource.h:31
#define LVIF_TEXT
Definition: commctrl.h:2281
#define LVCF_SUBITEM
Definition: commctrl.h:2561
UINT code
Definition: winuser.h:3112
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define IDS_DRIVE
Definition: resource.h:33
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
static const WCHAR szText[]
Definition: dialog.c:139
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
HWND hWnd
#define LVM_INSERTCOLUMNW
Definition: commctrl.h:2604
static WCHAR GetSelectedDriveLetter(VOID)
UINT_PTR idFrom
Definition: winuser.h:3111
#define LVM_INSERTITEM
Definition: commctrl.h:2378
#define IDC_MAINDEVICES
Definition: resource.h:9
#define SERVICE_RUNNING
Definition: winsvc.h:24
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
unsigned char BOOLEAN
#define IDS_MAPPEDIMAGE
Definition: resource.h:34
smooth NULL
Definition: ftsmooth.c:416
static INT_PTR CALLBACK DriverDialogProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
#define LVIS_SELECTED
Definition: commctrl.h:2291
#define FORCEINLINE
Definition: ntbasedef.h:221
FORCEINLINE DWORD Min(DWORD a, DWORD b)
LONG_PTR LPARAM
Definition: windef.h:208
LPTSTR szFilter
Definition: mplay32.c:30
static VOID ResetStats(VOID)
#define BM_GETCHECK
Definition: winuser.h:1879
#define SERVICE_QUERY_STATUS
Definition: winsvc.h:55
HWND hMountWnd
#define SW_SHOW
Definition: winuser.h:769
#define IDC_MAINSECTORS
Definition: resource.h:10
#define WM_SETTEXT
Definition: winuser.h:1599
#define OPEN_EXISTING
Definition: compat.h:426
#define WM_DESTROY
Definition: winuser.h:1591
#define IDC_MAINCONTROL
Definition: resource.h:19
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define IOCTL_VCDROM_CREATE_DRIVE
Definition: vcdioctl.h:2
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4917
#define OpenSCManager
Definition: winsvc.h:575
USHORT Count
Definition: vcdioctl.h:20
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define IDC_MOUNTUDF
Definition: resource.h:23
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDC_MOUNTIMAGE
Definition: resource.h:22
WCHAR wMountLetter
LPWSTR pszText
Definition: commctrl.h:2337
#define IOCTL_VCDROM_ENUMERATE_DRIVES
Definition: vcdioctl.h:5
#define WM_CLOSE
Definition: winuser.h:1603
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define WINAPI
Definition: msvc.h:8
LPWSTR pszText
Definition: commctrl.h:2539
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD nMaxFile
Definition: commdlg.h:368
#define LVM_SETEXTENDEDLISTVIEWSTYLE
Definition: commctrl.h:2696
BOOL WINAPI QueryServiceStatus(SC_HANDLE hService, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:2788
#define IDC_MAINOK
Definition: resource.h:8
UINT mask
Definition: commctrl.h:2332
CHAR Message[80]
Definition: alive.c:5
static INT_PTR CALLBACK MainDialogProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
static INT_PTR HandleDriverCommand(WPARAM wParam, LPARAM lParam)
#define IDC_MAINEJECT
Definition: resource.h:17
HWND hwndOwner
Definition: commdlg.h:361
#define LVM_SETITEMSTATE
Definition: commctrl.h:2644
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define IDD_DRIVERWINDOW
Definition: resource.h:5
#define IDC_DRIVERINSTALL
Definition: resource.h:27
static const WCHAR L[]
Definition: oid.c:1250
Definition: sacdrv.h:277
#define IDC_MAINTOTAL
Definition: resource.h:13
WCHAR Letter
static VOID AddDrive(VOID)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define IDC_MAINADD
Definition: resource.h:14
#define GENERIC_READ
Definition: compat.h:124
#define WM_COMMAND
Definition: winuser.h:1716
#define IOCTL_VCDROM_GET_IMAGE_PATH
Definition: vcdioctl.h:6
#define IDC_MOUNTJOLIET
Definition: resource.h:24
#define NM_CLICK
Definition: commctrl.h:130
UINT state
Definition: commctrl.h:2335
#define SERVICE_START
Definition: winsvc.h:57
Status
Definition: gdiplustypes.h:24
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define LVM_DELETEALLITEMS
Definition: commctrl.h:2385
#define LVCF_FMT
Definition: commctrl.h:2558
HWND hListView
Definition: gui.cpp:29
static INT_PTR HandleCommand(WPARAM wParam, LPARAM lParam)
HINSTANCE hInst
Definition: dxdiag.c:13
#define IDD_MOUNTWINDOW
Definition: resource.h:4
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define IDC_MOUNTPERSIST
Definition: resource.h:25
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define SERVICE_STOP
Definition: winsvc.h:58
WCHAR Path[255]
Definition: vcdioctl.h:10
INT_PTR QueryDriverInfo(HWND hDlg)
#define IOCTL_STORAGE_LOAD_MEDIA
Definition: ntddstor.h:99
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:619
#define LVM_SETITEM
Definition: commctrl.h:2371
unsigned int UINT
Definition: ndis.h:50
#define MOUNT_FLAG_SUPP_JOLIET
Definition: vcdioctl.h:16
#define IDC_MAINSIZE
Definition: resource.h:11
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
#define BST_CHECKED
Definition: winuser.h:197
#define SendMessage
Definition: winuser.h:5709
static VOID MountImage(VOID)
#define LVITEM
Definition: commctrl.h:2347
static VOID DriverControl(VOID)
HWND WINAPI CreateDialogParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
LPWSTR lpBinaryPathName
Definition: winsvc.h:159
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_QUERY_CONFIG
Definition: winsvc.h:53
WCHAR Drives[26]
Definition: vcdioctl.h:21
_In_ ULONG SectorSize
Definition: halfuncs.h:291
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
static VOID RemountImage(VOID)
#define IDC_DRIVERSTOP
Definition: resource.h:29
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LVIF_STATE
Definition: commctrl.h:2284
LONG_PTR LRESULT
Definition: windef.h:209
#define wsprintf
Definition: winuser.h:5731
#define LVM_GETNEXTITEM
Definition: commctrl.h:2405
#define IDD_MAINWINDOW
Definition: resource.h:3
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define IOCTL_VCDROM_DELETE_DRIVE
Definition: vcdioctl.h:3
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define HeapFree(x, y, z)
Definition: compat.h:394
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define RegCreateKeyEx
Definition: winreg.h:501
#define LoadString
Definition: winuser.h:5685
static VOID PerformMount(VOID)
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255
#define LVIS_FOCUSED
Definition: commctrl.h:2290
#define WM_NOTIFY
Definition: richedit.h:61
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
#define IDC_MAINFREE
Definition: resource.h:12
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
static VOID RefreshDevicesList(WCHAR Letter)
#define IDC_DRIVERREMOVE
Definition: resource.h:30
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define REG_SZ
Definition: layer.c:22
static VOID EjectDrive(VOID)