Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

377 lines
8.5 KiB

  1. // RCOptions.cpp : Defines the entry point for the DLL application.
  2. //
  3. #include "stdafx.h"
  4. #include <afx.h>
  5. #include <CPL.H>
  6. #include <windows.h>
  7. #include "resource.h"
  8. #include <stdio.h>
  9. #include <RACPLSettings.h>
  10. CRegKey g_cRegKey;
  11. static HINSTANCE g_hInstance;
  12. HMODULE g_hRASettings = NULL;
  13. pfnOpenRACPLSettings g_pfnOpen = NULL;
  14. pfnCloseRACPLSettings g_pfnClose = NULL;
  15. pfnGetRACPLSettings g_pfnGet = NULL;
  16. pfnSetRACPLSettings g_pfnSet = NULL;
  17. RACPLSETTINGS g_RACPLSettings;
  18. #define REG_VALUE_DATA_COLLECTION _T("RDC")
  19. #define REG_VALUE_PWD_ENCRYPT _T("PasswdEncryt")
  20. #define REG_BINARY_VALUE_NOTSET_RC 0
  21. //
  22. // Globals
  23. //
  24. TCHAR szMaxTimeOut[MAX_PATH];
  25. DWORD dwDataCollection = 0;
  26. DWORD dwEnableRC = REG_DWORD_RA_DISABLED;
  27. DWORD dwUnSolicited = 0;
  28. DWORD dwMaxTicket = 0;
  29. DWORD dwTrue = 1;
  30. DWORD dwFalse = 0;
  31. DWORD dwPasswdEncrypt = 0;
  32. DWORD InitDialog( HWND hwndDlg )
  33. {
  34. DWORD dwRetVal = S_OK;
  35. TCHAR szError[128];
  36. g_hRASettings = LoadLibrary( _T("RACPLSettings.dll") );
  37. if(NULL == g_hRASettings)
  38. {
  39. //
  40. // Error
  41. //
  42. _stprintf(szError, L"Error: %ld", GetLastError());
  43. MessageBox( GetFocus(), szError, _T("LoadLibrary failed"), 0);
  44. ExitThread(0);
  45. }
  46. g_pfnOpen = (pfnOpenRACPLSettings)GetProcAddress( g_hRASettings, "OpenRACPLSettings" );
  47. if(NULL == g_pfnOpen)
  48. {
  49. //
  50. // Error
  51. //
  52. _stprintf(szError, L"Error: %ld", GetLastError());
  53. MessageBox( GetFocus(), szError, _T("Failed to GetProcAddress of OpenRACPLSettings") , 0);
  54. ExitThread(0);
  55. }
  56. g_pfnClose = (pfnCloseRACPLSettings)GetProcAddress( g_hRASettings, "CloseRACPLSettings" );
  57. if(NULL == g_pfnClose)
  58. {
  59. //
  60. // Error
  61. //
  62. _stprintf(szError, L"Error: %ld", GetLastError());
  63. MessageBox( GetFocus(), szError, _T("Failed to GetProcAddress of CloseRACPLSettings") , 0);
  64. ExitThread(0);
  65. }
  66. g_pfnGet = (pfnGetRACPLSettings)GetProcAddress( g_hRASettings, "GetRACPLSettings" );
  67. if(NULL == g_pfnGet)
  68. {
  69. //
  70. // Error
  71. //
  72. _stprintf(szError, L"Error: %ld", GetLastError());
  73. MessageBox( GetFocus(), szError, _T("Failed to GetProcAddress of GetRACPLSettings"), 0);
  74. ExitThread(0);
  75. }
  76. g_pfnSet = (pfnSetRACPLSettings)GetProcAddress( g_hRASettings, "SetRACPLSettings" );
  77. if(NULL == g_pfnSet )
  78. {
  79. //
  80. // Error
  81. //
  82. _stprintf(szError, L"Error: %ld", GetLastError());
  83. MessageBox( GetFocus(),szError, _T("Failed to GetProcAddress of SetRACPLSettings"), 0);
  84. ExitThread(0);
  85. }
  86. //
  87. // Open the RACPLSettings
  88. //
  89. g_pfnOpen();
  90. //
  91. // Load the settings
  92. //
  93. dwRetVal = g_pfnGet(&g_RACPLSettings);
  94. if(S_OK != dwRetVal)
  95. {
  96. //
  97. // Error
  98. //
  99. _stprintf(szError, L"Error: %ld", GetLastError());
  100. MessageBox( GetFocus(), szError, _T("GetRACPLSettings failed"), 0);
  101. ExitThread(0);
  102. }
  103. //
  104. // Remote Assistance Mode
  105. //
  106. switch(g_RACPLSettings.dwMode)
  107. {
  108. case REG_DWORD_RA_DISABLED:
  109. CheckDlgButton(hwndDlg ,IDC_DISABLE_RC,BST_CHECKED);
  110. break;
  111. case REG_DWORD_RA_ENABLED:
  112. CheckDlgButton(hwndDlg ,IDC_ENABLE_RC,BST_CHECKED);
  113. break;
  114. case REG_DWORD_RA_SHADOWONLY:
  115. CheckDlgButton(hwndDlg ,IDC_SHADOW_ONLY,BST_CHECKED);
  116. break;
  117. default:
  118. _stprintf(szError, L"Unknown Remote Assitance Mode in registry", GetLastError());
  119. MessageBox( GetFocus(), szError, _T("Remote Assistance Mode"), 0);
  120. break;
  121. }
  122. //
  123. // Allow Unsolicited Remote Assistance
  124. //
  125. if (g_RACPLSettings.dwUnsolicited == REG_DWORD_RA_ALLOW)
  126. {
  127. CheckDlgButton(hwndDlg ,IDC_UNATTENDED,BST_CHECKED);
  128. }
  129. else if (g_RACPLSettings.dwUnsolicited == REG_DWORD_RA_DISALLOW)
  130. {
  131. CheckDlgButton(hwndDlg ,IDC_UNATTENDED,BST_UNCHECKED);
  132. }
  133. else
  134. {
  135. _stprintf(szError, L"Unknown Allow unsolicited RA value in registry", GetLastError());
  136. MessageBox( GetFocus(), szError, _T("Remote Assistance Mode"), 0);
  137. }
  138. //
  139. // Maximum Ticket Timeout
  140. //
  141. _stprintf(szMaxTimeOut, L"%d", g_RACPLSettings.dwMaxTimeout);
  142. SetWindowText(GetDlgItem(hwndDlg ,IDC_MAXIMUM_TICKET_TIMEOUT), szMaxTimeOut);
  143. return dwRetVal;
  144. }
  145. DWORD CommitChanges( HWND hwndDlg )
  146. {
  147. DWORD dwRetVal = S_OK;
  148. DWORD dwTimeout = 0;
  149. //
  150. // Remote Assistance Mode
  151. //
  152. if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_RC) == BST_CHECKED)
  153. {
  154. g_RACPLSettings.dwMode = REG_DWORD_RA_ENABLED;
  155. }
  156. else if (IsDlgButtonChecked(hwndDlg, IDC_DISABLE_RC) == BST_CHECKED)
  157. {
  158. g_RACPLSettings.dwMode = REG_DWORD_RA_DISABLED;
  159. }
  160. else
  161. {
  162. g_RACPLSettings.dwMode = REG_DWORD_RA_SHADOWONLY;
  163. }
  164. //
  165. // Allow Unsolicited Remote Assistance
  166. //
  167. if (IsDlgButtonChecked(hwndDlg, IDC_UNATTENDED) == BST_CHECKED)
  168. {
  169. g_RACPLSettings.dwUnsolicited = REG_DWORD_RA_ALLOW;
  170. }
  171. else
  172. {
  173. g_RACPLSettings.dwUnsolicited = REG_DWORD_RA_DISALLOW;
  174. }
  175. //
  176. // Ticket Timeout
  177. //
  178. GetWindowText(GetDlgItem(hwndDlg ,IDC_MAXIMUM_TICKET_TIMEOUT), szMaxTimeOut, MAX_PATH);
  179. _stscanf( szMaxTimeOut, _T("%d"), &dwTimeout );
  180. g_RACPLSettings.dwMaxTimeout = dwTimeout;
  181. //
  182. // Write the settings to registry
  183. //
  184. if( S_OK != g_pfnSet( &g_RACPLSettings ))
  185. {
  186. //
  187. // Error
  188. //
  189. MessageBox( GetFocus(), _T("SetRACPLSettings failed"), _T("Error"), 0);
  190. }
  191. return dwRetVal;
  192. }
  193. // **************************************************************************
  194. INT_PTR CALLBACK DialogBoxCallBack(HWND hwndDlg, UINT uMsg, WPARAM wParam,
  195. LPARAM lParam)
  196. {
  197. WORD wRes = 0;
  198. DWORD dwRetVal = S_OK;
  199. TCHAR szError[128];
  200. switch(uMsg)
  201. {
  202. case WM_COMMAND:
  203. wRes = LOWORD(wParam);
  204. switch(LOWORD(wParam))
  205. {
  206. case IDACCEPT:
  207. CommitChanges( hwndDlg );
  208. EnableWindow(GetDlgItem(hwndDlg ,IDACCEPT),false);
  209. break;
  210. case IDOK:
  211. CommitChanges( hwndDlg );
  212. //
  213. // Close down RACPLSettings API
  214. //
  215. g_pfnClose();
  216. EndDialog(hwndDlg, wRes);
  217. break;
  218. case IDC_UNATTENDED:
  219. EnableWindow(GetDlgItem(hwndDlg ,IDACCEPT),true);
  220. break;
  221. case IDCANCEL:
  222. EndDialog(hwndDlg, wRes);
  223. break;
  224. case IDC_ENABLE_RC:
  225. dwEnableRC = REG_DWORD_RA_ENABLED;
  226. EnableWindow(GetDlgItem(hwndDlg ,IDACCEPT),true);
  227. break;
  228. case IDC_DISABLE_RC:
  229. dwEnableRC = REG_DWORD_RA_DISABLED;
  230. EnableWindow(GetDlgItem(hwndDlg ,IDACCEPT),true);
  231. break;
  232. case IDC_SHADOW_ONLY:
  233. dwEnableRC = REG_DWORD_RA_SHADOWONLY;
  234. EnableWindow(GetDlgItem(hwndDlg ,IDACCEPT),true);
  235. break;
  236. case IDC_MAXIMUM_TICKET_TIMEOUT:
  237. GetWindowText(GetDlgItem(hwndDlg ,IDC_MAXIMUM_TICKET_TIMEOUT), szMaxTimeOut,MAX_PATH);
  238. EnableWindow(GetDlgItem(hwndDlg ,IDACCEPT),true);
  239. break;
  240. default:
  241. break;
  242. }
  243. break;
  244. case WM_INITDIALOG:
  245. InitDialog( hwndDlg );
  246. break;
  247. }
  248. return FALSE;
  249. }
  250. extern "C"
  251. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  252. {
  253. g_hInstance = hInstance;
  254. return TRUE;
  255. }
  256. LONG CPlApplet(
  257. HWND hwndCPl,
  258. UINT uMsg,
  259. LONG lParam1,
  260. LONG lParam2
  261. )
  262. {
  263. INT_PTR nResDlg = NULL;
  264. LPCPLINFO lpCPlInfo;
  265. switch (uMsg)
  266. {
  267. case ( CPL_INIT ) :
  268. {
  269. return true;
  270. }
  271. case ( CPL_EXIT ) :
  272. {
  273. break;
  274. }
  275. case ( CPL_STOP ) :
  276. {
  277. break;
  278. }
  279. case ( CPL_GETCOUNT ) :
  280. {
  281. return 1;
  282. }
  283. case ( CPL_INQUIRE ) :
  284. {
  285. lpCPlInfo = (LPCPLINFO)lParam2;
  286. lpCPlInfo->idIcon = ID_ICON;
  287. lpCPlInfo->idName = IDS_NAME;
  288. lpCPlInfo->idInfo = IDS_INFO;
  289. return true;
  290. }
  291. case ( CPL_NEWINQUIRE ) :
  292. {
  293. return true;
  294. }
  295. case ( CPL_DBLCLK ) :
  296. case ( CPL_STARTWPARMS ) :
  297. {
  298. nResDlg = DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_SETOPTIONS), NULL,
  299. (int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))DialogBoxCallBack);
  300. return true;
  301. }
  302. }
  303. return true;
  304. }