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.

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