ReactOS  0.4.11-dev-946-g431643b
create.c File Reference
#include "precomp.h"
Include dependency graph for create.c:

Go to the source code of this file.

Classes

struct  _CREATE_DATA
 

Typedefs

typedef struct _CREATE_DATA CREATE_DATA
 
typedef struct _CREATE_DATAPCREATE_DATA
 

Functions

static BOOL DoCreate (PCREATE_DATA Data)
 
static LPWSTR GetStringFromDialog (PCREATE_DATA Data, UINT id)
 
static BOOL GetDataFromDialog (PCREATE_DATA Data)
 
static VOID FreeMemory (PCREATE_DATA Data)
 
INT_PTR CALLBACK CreateHelpDialogProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 
INT_PTR CALLBACK CreateDialogProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 

Variables

static BOOL bHelpOpen = FALSE
 

Typedef Documentation

◆ CREATE_DATA

◆ PCREATE_DATA

Function Documentation

◆ CreateDialogProc()

INT_PTR CALLBACK CreateDialogProc ( HWND  hDlg,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 218 of file create.c.

Referenced by MainWndCommand().

222 {
223  HICON hIcon = NULL;
224 
225  switch (message)
226  {
227  case WM_INITDIALOG:
228  {
229  hIcon = (HICON)LoadImage(hInstance,
231  IMAGE_ICON,
232  16,
233  16,
234  0);
235  if (hIcon)
236  {
237  SendMessage(hDlg,
238  WM_SETICON,
239  ICON_SMALL,
240  (LPARAM)hIcon);
241  DestroyIcon(hIcon);
242  }
243 
244  return TRUE;
245  }
246 
247  case WM_COMMAND:
248  {
249  switch (LOWORD(wParam))
250  {
251  case IDOK:
252  {
254 
257  sizeof(CREATE_DATA));
258  if (Data)
259  {
260  Data->hSelf = hDlg;
261 
262  if (GetDataFromDialog(Data))
263  {
264  DoCreate(Data);
265  }
266  else
267  {
268  /* Something went wrong, leave the dialog
269  * open so they can try again */
270  FreeMemory(Data);
271  break;
272  }
273 
274  FreeMemory(Data);
275  }
276 
277  EndDialog(hDlg,
278  LOWORD(wParam));
279  return TRUE;
280  }
281 
282  case IDCANCEL:
283  {
284  EndDialog(hDlg,
285  LOWORD(wParam));
286  return TRUE;
287  }
288 
289  case ID_CREATE_HELP:
290  {
291  HWND hHelp;
292 
293  if (! bHelpOpen)
294  {
295  hHelp = CreateDialog(hInstance,
297  hDlg,
299  if(hHelp != NULL)
300  {
301  bHelpOpen = TRUE;
302  }
303  }
304  }
305  break;
306  }
307  }
308  }
309 
310  return FALSE;
311 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
static VOID FreeMemory(PCREATE_DATA Data)
Definition: create.c:134
Definition: tftpd.h:59
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
#define IMAGE_ICON
Definition: winuser.h:212
struct _CREATE_DATA * PCREATE_DATA
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
#define ID_CREATE_HELP
Definition: resource.h:189
#define IDD_DLG_HELP_OPTIONS
Definition: resource.h:190
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define ICON_SMALL
Definition: tnclass.cpp:48
HINSTANCE hInstance
Definition: charmap.c:20
LONG_PTR LPARAM
Definition: windef.h:208
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND hSelf
Definition: create.c:14
static BOOL GetDataFromDialog(PCREATE_DATA Data)
Definition: create.c:112
#define WM_COMMAND
Definition: winuser.h:1716
HANDLE ProcessHeap
Definition: servman.c:15
static BOOL DoCreate(PCREATE_DATA Data)
Definition: create.c:26
HICON hIcon
Definition: msconfig.c:44
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
INT_PTR CALLBACK CreateHelpDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: create.c:163
#define IDI_SM_ICON
Definition: resource.h:66
#define SendMessage
Definition: winuser.h:5709
#define LoadImage
Definition: winuser.h:5681
#define IDCANCEL
Definition: winuser.h:825
static BOOL bHelpOpen
Definition: create.c:23
#define WM_INITDIALOG
Definition: winuser.h:1715
#define LOWORD(l)
Definition: pedump.c:82
#define CreateDialog
Definition: winuser.h:5615

◆ CreateHelpDialogProc()

INT_PTR CALLBACK CreateHelpDialogProc ( HWND  hDlg,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 163 of file create.c.

Referenced by CreateDialogProc().

167 {
168  HWND hHelp;
169  HICON hIcon = NULL;
170  WCHAR Buf[1000];
171 
172  switch (message)
173  {
174  case WM_INITDIALOG:
175  {
176  hIcon = (HICON) LoadImageW(hInstance,
178  IMAGE_ICON,
179  16,
180  16,
181  0);
182 
183  SendMessageW(hDlg,
184  WM_SETICON,
185  ICON_SMALL,
186  (LPARAM)hIcon);
187 
188  hHelp = GetDlgItem(hDlg,
190 
193  Buf,
194  sizeof(Buf) / sizeof(WCHAR));
195 
196  SetWindowTextW(hHelp, Buf);
197 
198  return TRUE;
199  }
200 
201  case WM_COMMAND:
202  {
203  if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
204  {
205  bHelpOpen = FALSE;
206  DestroyIcon(hIcon);
207  DestroyWindow(hDlg);
208  return TRUE;
209  }
210  break;
211  }
212  }
213 
214  return FALSE;
215 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
Definition: tftpd.h:59
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
#define IMAGE_ICON
Definition: winuser.h:212
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
BOOL WINAPI DestroyWindow(_In_ HWND)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
WPARAM wParam
Definition: combotst.c:138
#define ICON_SMALL
Definition: tnclass.cpp:48
HINSTANCE hInstance
Definition: charmap.c:20
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
LONG_PTR LPARAM
Definition: windef.h:208
#define IDS_HELP_OPTIONS
Definition: resource.h:192
smooth NULL
Definition: ftsmooth.c:416
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDC_CREATE_HELP
Definition: resource.h:191
#define WM_COMMAND
Definition: winuser.h:1716
HICON hIcon
Definition: msconfig.c:44
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDI_SM_ICON
Definition: resource.h:66
#define IDCANCEL
Definition: winuser.h:825
static BOOL bHelpOpen
Definition: create.c:23
#define WM_INITDIALOG
Definition: winuser.h:1715
#define LOWORD(l)
Definition: pedump.c:82

◆ DoCreate()

static BOOL DoCreate ( PCREATE_DATA  Data)
static

Definition at line 26 of file create.c.

Referenced by CreateDialogProc().

27 {
28  SC_HANDLE hSCManager;
29  SC_HANDLE hSc;
30  BOOL bRet = FALSE;
31 
32  /* open handle to the SCM */
33  hSCManager = OpenSCManagerW(NULL,
34  NULL,
36  if (hSCManager)
37  {
38  hSc = CreateServiceW(hSCManager,
39  Data->ServiceName,
40  Data->DisplayName,
45  Data->BinPath,
46  NULL,
47  NULL,
48  NULL,
49  NULL,
50  NULL);
51 
52  if (hSc)
53  {
54  LPWSTR lpSuccess;
55 
56  /* Set the service description as CreateService
57  does not do this for us */
59  Data->Description);
60 
61  /* report success to user */
62  if (AllocAndLoadString(&lpSuccess,
63  hInstance,
65  {
66  DisplayString(lpSuccess);
67 
68  LocalFree(lpSuccess);
69  }
70 
71  CloseServiceHandle(hSc);
72  bRet = TRUE;
73  }
74 
75  CloseServiceHandle(hSCManager);
76  }
77 
78  return bRet;
79 }
#define SERVICE_ERROR_NORMAL
Definition: cmtypes.h:980
#define TRUE
Definition: types.h:120
SC_HANDLE WINAPI CreateServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, LPCWSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, LPCWSTR lpPassword)
Definition: scm.c:807
LPWSTR Description
Definition: create.c:18
BOOL SetServiceDescription(LPWSTR lpServiceName, LPWSTR lpDescription)
Definition: query.c:210
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
static INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:60
HINSTANCE hInstance
Definition: charmap.c:20
#define IDS_CREATE_SUCCESS
Definition: resource.h:193
LPWSTR BinPath
Definition: create.c:17
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
unsigned int BOOL
Definition: ntddk_ex.h:94
LPWSTR DisplayName
Definition: create.c:16
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2010
VOID DisplayString(LPWSTR Msg)
Definition: misc.c:211
SC_HANDLE hSCManager
Definition: sc.c:12
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
LPWSTR ServiceName
Definition: create.c:15
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define SERVICE_DEMAND_START
Definition: cmtypes.h:976

◆ FreeMemory()

static VOID FreeMemory ( PCREATE_DATA  Data)
static

Definition at line 134 of file create.c.

Referenced by CompleteIO(), CreateDialogProc(), CreateSoundThread(), DestroySoundThread(), DetectNt4SoundDevices(), DoWaveStreaming(), EnumerateNt4ServiceSoundDevices(), FreeSoundDevice(), FreeSoundDeviceInstance(), KmtFltSendBufferToDriver(), OpenSoundDeviceRegKey(), OpenSoundDriverParametersRegKey(), and UnprepareWaveHeader().

135 {
136  if (Data->ServiceName != NULL)
138  0,
139  Data->ServiceName);
140  if (Data->DisplayName != NULL)
142  0,
143  Data->DisplayName);
144  if (Data->BinPath != NULL)
146  0,
147  Data->BinPath);
148  if (Data->Description != NULL)
150  0,
151  Data->Description);
152  if (Data->Options != NULL)
154  0,
155  Data->Options);
156 
158  0,
159  Data);
160 }
LPWSTR Description
Definition: create.c:18
LPWSTR Options
Definition: create.c:19
LPWSTR BinPath
Definition: create.c:17
smooth NULL
Definition: ftsmooth.c:416
LPWSTR DisplayName
Definition: create.c:16
HANDLE ProcessHeap
Definition: servman.c:15
LPWSTR ServiceName
Definition: create.c:15
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ GetDataFromDialog()

static BOOL GetDataFromDialog ( PCREATE_DATA  Data)
static

Definition at line 112 of file create.c.

Referenced by CreateDialogProc().

113 {
114  BOOL bRet = FALSE;
115 
117  {
119  {
120  if ((Data->BinPath = GetStringFromDialog(Data, IDC_CREATE_PATH)))
121  {
124 
125  bRet = TRUE;
126  }
127  }
128  }
129 
130  return bRet;
131 }
static LPWSTR GetStringFromDialog(PCREATE_DATA Data, UINT id)
Definition: create.c:82
#define TRUE
Definition: types.h:120
#define IDC_CREATE_DISPNAME
Definition: resource.h:185
#define IDC_CREATE_DESC
Definition: resource.h:187
LPWSTR Description
Definition: create.c:18
#define IDC_CREATE_SERVNAME
Definition: resource.h:184
LPWSTR Options
Definition: create.c:19
#define IDC_CREATE_OPTIONS
Definition: resource.h:188
LPWSTR BinPath
Definition: create.c:17
unsigned int BOOL
Definition: ntddk_ex.h:94
LPWSTR DisplayName
Definition: create.c:16
#define IDC_CREATE_PATH
Definition: resource.h:186
LPWSTR ServiceName
Definition: create.c:15

◆ GetStringFromDialog()

static LPWSTR GetStringFromDialog ( PCREATE_DATA  Data,
UINT  id 
)
static

Definition at line 82 of file create.c.

Referenced by GetDataFromDialog().

84 {
85  HWND hwnd;
86  LPWSTR lpString = NULL;
87  INT iLen = 0;
88 
89  hwnd = GetDlgItem(Data->hSelf,
90  id);
91  if (hwnd)
92  {
93  iLen = GetWindowTextLengthW(hwnd);
94  if (iLen)
95  {
96  lpString = (LPWSTR)HeapAlloc(ProcessHeap,
97  0,
98  (iLen + 1) * sizeof(WCHAR));
99  if (lpString)
100  {
101  GetWindowTextW(hwnd,
102  lpString,
103  iLen + 1);
104  }
105  }
106  }
107 
108  return lpString;
109 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define WCHAR
Definition: msvc.h:43
int32_t INT
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND hSelf
Definition: create.c:14
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
int WINAPI GetWindowTextLengthW(_In_ HWND)
HANDLE ProcessHeap
Definition: servman.c:15
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1378
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Variable Documentation

◆ bHelpOpen

BOOL bHelpOpen = FALSE
static

Definition at line 23 of file create.c.

Referenced by CreateDialogProc(), and CreateHelpDialogProc().