Leaked source code of windows server 2003
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.

439 lines
9.5 KiB

  1. //
  2. // Copyright 1997 - Microsoft
  3. //
  4. //
  5. // NEWCMPTR.CPP - The "New Client" dialog box
  6. //
  7. #include "pch.h"
  8. #include "newcmptr.h"
  9. #include "mangdlg.h"
  10. #include "ccomputr.h"
  11. DEFINE_MODULE("IMADMUI")
  12. DEFINE_THISCLASS("CNewComputerExtensions")
  13. #define THISCLASS CNewComputerExtensions
  14. #define LPTHISCLASS LPCNewComputerExtensions
  15. //
  16. // CNewComputerExtensions_CreateInstance( )
  17. //
  18. LPVOID
  19. CNewComputerExtensions_CreateInstance( void )
  20. {
  21. TraceFunc( "CNewComputerExtensions_CreateInstance()\n" );
  22. LPTHISCLASS lpcc = new THISCLASS( );
  23. if ( !lpcc ) {
  24. RETURN(lpcc);
  25. }
  26. HRESULT hr = THR( lpcc->Init( ) );
  27. if ( FAILED(hr) ) {
  28. delete lpcc;
  29. RETURN(NULL);
  30. }
  31. RETURN(lpcc);
  32. }
  33. //
  34. // Constructor
  35. //
  36. THISCLASS::THISCLASS( ) :
  37. _padsContainerObj(NULL),
  38. _pManagedDialog(NULL),
  39. _pHostServerDialog(NULL),
  40. _pads(NULL),
  41. _fActivatePages(FALSE),
  42. _pszWizTitle(NULL),
  43. _pszContDisplayName(NULL),
  44. _hIcon(NULL)
  45. {
  46. TraceClsFunc( "CNewComputerExtensions( )\n" );
  47. InterlockIncrement( g_cObjects );
  48. TraceFuncExit();
  49. }
  50. //
  51. // Init( )
  52. //
  53. HRESULT
  54. THISCLASS::Init( )
  55. {
  56. TraceClsFunc( "Init( )\n" );
  57. HRESULT hr;
  58. // IUnknown stuff
  59. BEGIN_QITABLE_IMP( CNewComputerExtensions, IDsAdminNewObjExt );
  60. QITABLE_IMP( IDsAdminNewObjExt );
  61. END_QITABLE_IMP( CNewComputerExtensions );
  62. Assert( _cRef == 0);
  63. AddRef( );
  64. hr = CheckClipboardFormats( );
  65. Assert( !_padsContainerObj );
  66. Assert( !_pManagedDialog );
  67. Assert( !_pHostServerDialog );
  68. Assert( !_pszWizTitle );
  69. Assert( !_pszContDisplayName );
  70. Assert( !_hIcon );
  71. HRETURN(hr);
  72. }
  73. //
  74. // Destructor
  75. //
  76. THISCLASS::~THISCLASS( )
  77. {
  78. TraceClsFunc( "~CNewComputerExtensions( )\n" );
  79. if ( _padsContainerObj )
  80. _padsContainerObj->Release( );
  81. if ( _pszWizTitle )
  82. TraceFree( _pszWizTitle );
  83. if ( _pszContDisplayName )
  84. TraceFree( _pszContDisplayName );
  85. InterlockDecrement( g_cObjects );
  86. TraceFuncExit();
  87. }
  88. // ************************************************************************
  89. //
  90. // IUnknown
  91. //
  92. // ************************************************************************
  93. //
  94. // QueryInterface()
  95. //
  96. STDMETHODIMP
  97. THISCLASS::QueryInterface(
  98. REFIID riid,
  99. LPVOID *ppv )
  100. {
  101. TraceClsFunc( "" );
  102. HRESULT hr = ::QueryInterface( this, _QITable, riid, ppv );
  103. QIRETURN( hr, riid );
  104. }
  105. //
  106. // AddRef()
  107. //
  108. STDMETHODIMP_(ULONG)
  109. THISCLASS::AddRef( void )
  110. {
  111. TraceClsFunc( "[IUnknown] AddRef( )\n" );
  112. InterlockIncrement( _cRef );
  113. RETURN(_cRef);
  114. }
  115. //
  116. // Release()
  117. //
  118. STDMETHODIMP_(ULONG)
  119. THISCLASS::Release( void )
  120. {
  121. TraceClsFunc( "[IUnknown] Release( )\n" );
  122. InterlockDecrement( _cRef );
  123. if ( _cRef )
  124. RETURN(_cRef);
  125. TraceDo( delete this );
  126. RETURN(0);
  127. }
  128. // ************************************************************************
  129. //
  130. // IDsAdminNewObjExt
  131. //
  132. // ************************************************************************
  133. //
  134. // Initialize( )
  135. //
  136. STDMETHODIMP
  137. THISCLASS::Initialize(IADsContainer* pADsContainerObj,
  138. IADs* pADsCopySource,
  139. LPCWSTR lpszClassName,
  140. IDsAdminNewObj* pDsAdminNewObj,
  141. LPDSA_NEWOBJ_DISPINFO pDispInfo)
  142. {
  143. TraceClsFunc( "[IDsAdminNewObjExt] Initialize(" );
  144. TraceMsg( TF_FUNC, " pADsContainerObj = 0x%08x, lpszClassName = '%s', pDispInfo = 0x%08x )\n",
  145. pADsContainerObj, lpszClassName, pDispInfo );
  146. UNREFERENCED_PARAMETER(pADsCopySource);
  147. if ( !pADsContainerObj || !pDispInfo || !lpszClassName ) {
  148. HRETURN(E_POINTER);
  149. }
  150. if ( pDispInfo->dwSize != sizeof(*pDispInfo) ) {
  151. HRETURN(E_INVALIDARG);
  152. }
  153. if ( _wcsicmp( lpszClassName, COMPUTER_CLASS_NAME ) !=0 )
  154. HRETURN(E_INVALIDARG);
  155. HRESULT hr = S_OK;
  156. _padsContainerObj = pADsContainerObj;
  157. _padsContainerObj->AddRef( );
  158. // deep copy DSA_NEWOBJ_DISPINFO
  159. _pszWizTitle = (LPWSTR) TraceStrDup( pDispInfo->lpszWizTitle );
  160. _pszContDisplayName = (LPWSTR) TraceStrDup( pDispInfo->lpszContDisplayName );
  161. _hIcon = pDispInfo->hObjClassIcon;
  162. if (!_pszWizTitle || !_pszContDisplayName) {
  163. hr = E_OUTOFMEMORY;
  164. }
  165. HRETURN(hr);
  166. }
  167. //
  168. // AddPages( )
  169. //
  170. STDMETHODIMP
  171. THISCLASS::AddPages(
  172. LPFNADDPROPSHEETPAGE lpfnAddPage,
  173. LPARAM lParam)
  174. {
  175. TraceClsFunc( "[IDsAdminNewObjExt] AddPages(" );
  176. TraceMsg( TF_FUNC, " lpfnAddPage = 0x%08x, lParam = 0x%08x )\n", lpfnAddPage, lParam );
  177. HRESULT hr;
  178. hr = THR( ::AddPagesEx( (ITab**)&_pManagedDialog,
  179. CManagedPage_CreateInstance,
  180. lpfnAddPage,
  181. lParam,
  182. (LPUNKNOWN) NULL ) );
  183. if (FAILED( hr ))
  184. goto Error;
  185. _pManagedDialog->_pNewComputerExtension = this;
  186. _pManagedDialog->AllowActivation( &_fActivatePages );
  187. hr = THR( ::AddPagesEx( (ITab**)&_pHostServerDialog,
  188. CHostServerPage_CreateInstance,
  189. lpfnAddPage,
  190. lParam,
  191. (LPUNKNOWN) NULL ) );
  192. if (FAILED( hr ))
  193. goto Error;
  194. _pHostServerDialog->_pNewComputerExtension = this;
  195. _pHostServerDialog->AllowActivation( &_fActivatePages );
  196. Error:
  197. HRETURN(hr);
  198. }
  199. //
  200. // SetObject( )
  201. //
  202. STDMETHODIMP
  203. THISCLASS::SetObject(
  204. IADs* pADsObj)
  205. {
  206. TraceClsFunc( "[IDsAdminNewObjExt] SetObject(" );
  207. TraceMsg( TF_FUNC, " pADsObj = 0x%08x )\n", pADsObj );
  208. if ( !pADsObj )
  209. HRETURN(E_POINTER);
  210. HRESULT hr = S_OK;
  211. _pads = pADsObj;
  212. _pads->AddRef( );
  213. HRETURN(hr);
  214. }
  215. //
  216. // WriteData( )
  217. //
  218. STDMETHODIMP
  219. THISCLASS::WriteData(
  220. HWND hWnd,
  221. ULONG uContext)
  222. {
  223. TraceClsFunc( "[IDsAdminNewObjExt] WriteData(" );
  224. TraceMsg( TF_FUNC, " hWnd = 0x%08x, uContext = %d )\n", hWnd, uContext );
  225. HRESULT hr = S_OK;
  226. LPWSTR pszGuid = NULL;
  227. LPWSTR pszServer = NULL;
  228. LPCOMPUTER lpc = NULL;
  229. //
  230. // we should set our data during PRECOMMIT, so that the data
  231. // get's set during the initial SetCommit(). This way we never have
  232. // to actually commit the data ourselves.
  233. //
  234. if ( uContext != DSA_NEWOBJ_CTX_PRECOMMIT ) {
  235. goto Cleanup;
  236. }
  237. lpc = (LPCOMPUTER) CreateIntelliMirrorClientComputer( _pads );
  238. if ( !lpc )
  239. goto Error;
  240. hr = THR( _pManagedDialog->QueryInformation( NETBOOTGUID, &pszGuid ) );
  241. if (FAILED( hr )) {
  242. goto Error;
  243. }
  244. if ( pszGuid && pszGuid[0] ) {
  245. hr = THR( lpc->SetGUID( pszGuid ) );
  246. if (FAILED( hr ))
  247. goto Error;
  248. }
  249. hr = THR( _pHostServerDialog->QueryInformation( NETBOOTSERVER, &pszServer ) );
  250. if (FAILED( hr ))
  251. goto Error;
  252. if ( pszServer && pszServer[0] ) {
  253. hr = THR( lpc->SetServerName( pszServer ) );
  254. if (FAILED( hr ))
  255. goto Error;
  256. }
  257. Assert( hr == S_OK );
  258. Cleanup:
  259. if ( pszGuid ){
  260. TraceFree( pszGuid );
  261. }
  262. if ( pszServer ){
  263. TraceFree( pszServer );
  264. }
  265. if ( lpc ) {
  266. lpc->Release( );
  267. }
  268. HRETURN(hr);
  269. Error:
  270. MessageBoxFromHResult( NULL, IDS_ERROR_WRITINGTOCOMPUTERACCOUNT, hr );
  271. goto Cleanup;
  272. }
  273. //
  274. // OnError( )
  275. //
  276. STDMETHODIMP
  277. THISCLASS::OnError(
  278. HWND hWnd,
  279. HRESULT hr,
  280. ULONG uContext)
  281. {
  282. TraceClsFunc( "[IDsAdminNewObjExt] OnError(" );
  283. TraceMsg( TF_FUNC, " hWnd = 0x%08x, uContext = %d )\n", hWnd, uContext );
  284. HRESULT hrRet = E_NOTIMPL;
  285. HRETURN(hrRet);
  286. }
  287. //
  288. // GetSummaryInfo( )
  289. //
  290. STDMETHODIMP
  291. THISCLASS::GetSummaryInfo(
  292. BSTR* pBstrText)
  293. {
  294. TraceClsFunc( "[IDsAdminNewObjExt] GetSummaryInfo( ... )\n" );
  295. if ( !pBstrText )
  296. HRETURN(E_POINTER);
  297. HRESULT hr;
  298. DWORD dw;
  299. WCHAR szManagedPC[ 256 ];
  300. LPWSTR pszGuid = NULL;
  301. LPWSTR pszServer = NULL;
  302. LPWSTR pszOut = NULL;
  303. *pBstrText = NULL;
  304. hr = _pManagedDialog->QueryInformation( L"Guid", &pszGuid );
  305. if (FAILED(hr) ||pszGuid == NULL) {
  306. goto Cleanup;
  307. }
  308. dw = LoadString( g_hInstance, IDS_MANAGED_PC, szManagedPC, ARRAYSIZE(szManagedPC) );
  309. Assert( dw );
  310. if (!dw) {
  311. hr = E_FAIL;
  312. goto Cleanup;
  313. }
  314. hr = THR( _pHostServerDialog->QueryInformation( L"Server", &pszServer ) );
  315. if ( FAILED(hr) ) {
  316. goto Cleanup;
  317. }
  318. // Make a buffer
  319. dw += wcslen( pszGuid ) + 1;
  320. if ( pszServer ) {
  321. dw += wcslen( pszServer ) + 1;
  322. }
  323. if (!(pszOut = (LPWSTR) TraceAllocString( LMEM_FIXED, dw )) ||
  324. _snwprintf(
  325. pszOut,
  326. dw,
  327. szManagedPC,
  328. pszGuid,
  329. pszServer) < 0 ) {
  330. hr = E_OUTOFMEMORY;
  331. goto Cleanup;
  332. }
  333. *pBstrText = SysAllocString( pszOut );
  334. if ( !*pBstrText ) {
  335. hr = E_OUTOFMEMORY;
  336. goto Cleanup;
  337. }
  338. hr = S_OK;
  339. Cleanup:
  340. if ( pszOut )
  341. TraceFree( pszOut );
  342. if ( pszServer )
  343. TraceFree( pszServer );
  344. if ( pszGuid )
  345. TraceFree( pszGuid );
  346. HRETURN(hr);
  347. }