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.

1584 lines
38 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. // MOENGINE.CPP
  6. //
  7. // Purpose: Code-generation engine for HMM* providers
  8. //
  9. // Comments:
  10. //
  11. /**************************************************************************
  12. -- .
  13. Generates .CPP, .H, .MAK, .DEF, files for providers
  14. MOProviderOpen() : Provider initialization
  15. MOProviderCancel() : Cancels construction of current provider
  16. MOProviderClose() : Provider cleanup, writes provider files
  17. MOPropSetOpen() : Property set initialization
  18. MOPropSetCancel() : Cancels construction of target property set
  19. MOPropertyAdd() : Adds property to target property set
  20. MOPropertyAttribSet() : Sets attributes of pre-existing property
  21. MOGetLastError() : Returns code of last error encountered
  22. MOResetLastError() : Clears recorded error code
  23. Revisions:
  24. 09/17/96 a-jmoon created
  25. 1/22/98 a-brads updated to new framework
  26. String substitutions:
  27. Designator Description
  28. ========== =======================
  29. %%1 Provider base file name
  30. %%2 Provider description
  31. %%3 HMMS type library path
  32. %%4 Library UUID
  33. %%5 Provider UUID
  34. %%6 System directory
  35. %%7 Property set base file name
  36. %%8 Property set description
  37. %%9 Property set name
  38. %%A Property set UUID
  39. %%B Property set class name
  40. %%C Property set parent class name
  41. %%D Property name definitions
  42. %%E Property enumerations (TPROP)
  43. %%F Property name extern definitions
  44. %%G Property template declarations
  45. %%H Property PUT methods
  46. %%I Property GET methods
  47. %%J Upper-cased property set base file name
  48. %%K Attribute assignments
  49. **************************************************************************/
  50. #include "precomp.h"
  51. #include <stdio.h>
  52. #include <conio.h>
  53. #include <io.h>
  54. #include <comdef.h>
  55. #define POLARITY
  56. #include <chstring.h>
  57. #define MO_ENGINE_PROGRAM
  58. #include <moengine.h>
  59. #include "resource.h"
  60. HINSTANCE hOurAFXResourceHandle ;
  61. PROVIDER_INFO *pProviderList = NULL ;
  62. CHString sSystemDirectory ;
  63. DWORD dwLastError ;
  64. /*****************************************************************************
  65. *
  66. * FUNCTION : DLLMain
  67. *
  68. * DESCRIPTION : DLL entry function
  69. *
  70. * INPUTS :
  71. *
  72. * OUTPUTS :
  73. *
  74. * RETURNS : TRUE
  75. *
  76. * COMMENTS : Saves our DLL's instance handle, gets system directory
  77. *
  78. *****************************************************************************/
  79. BOOL APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReasonForCall, LPVOID pReserved)
  80. {
  81. WCHAR szTemp[_MAX_PATH] ;
  82. UNREFERENCED_PARAMETER(hInstance) ;
  83. UNREFERENCED_PARAMETER(dwReasonForCall) ;
  84. UNREFERENCED_PARAMETER(pReserved) ;
  85. hOurAFXResourceHandle = GetModuleHandle(_T("MOENGINE.DLL")) ;
  86. GetSystemDirectory(szTemp, sizeof(szTemp)/sizeof(WCHAR)) ;
  87. sSystemDirectory = szTemp ;
  88. sSystemDirectory += _T("\\") ;
  89. // This directory is quoted in the IDL file, so needs double backslashes
  90. //======================================================================
  91. DoubleBackslash(sSystemDirectory) ;
  92. return TRUE;
  93. }
  94. /*****************************************************************************
  95. *
  96. * FUNCTION : MOProviderOpen
  97. *
  98. * DESCRIPTION : Initializes provider data
  99. *
  100. * INPUTS :
  101. *
  102. * OUTPUTS :
  103. *
  104. * RETURNS :
  105. *
  106. * COMMENTS :
  107. *
  108. *****************************************************************************/
  109. DllExport DWORD MOProviderOpen(LPCWSTR pszBaseName,
  110. LPCWSTR pszDescription,
  111. LPCWSTR pszOutputPath,
  112. LPCWSTR pszTLBPath,
  113. LPCWSTR pszLibraryUUID,
  114. LPCWSTR pszProviderUUID)
  115. {
  116. PROVIDER_INFO *pProvider, *pTemp ;
  117. // Base file name is the only rejection criterion
  118. //===============================================
  119. if(!pszBaseName || !pszBaseName[0])
  120. {
  121. // As odd as this looks, it's what the ui is expecting.
  122. dwLastError = MO_ERROR_INVALID_FILENAME ;
  123. return MO_INVALID_ID ;
  124. }
  125. // Create a new provider record
  126. //=============================
  127. pProvider = new PROVIDER_INFO ;
  128. if(pProvider == NULL)
  129. {
  130. // As odd as this looks, it's what the ui is expecting.
  131. dwLastError = MO_ERROR_MEMORY ;
  132. return MO_INVALID_ID ;
  133. }
  134. pProvider->dwProviderID = MONewProviderID() ;
  135. // Verify input data & construct provider record
  136. //==============================================
  137. pProvider->sBaseName = pszBaseName ;
  138. pProvider->sDescription = pszDescription ? CHString(pszDescription) : _T("") ;
  139. pProvider->sOutputPath = pszOutputPath && pszOutputPath[0] ? CHString(pszOutputPath) : _T(".") ;
  140. pProvider->sTLBPath = pszTLBPath && pszTLBPath[0] ? CHString(pszTLBPath) : _T(".") ;
  141. pProvider->sLibraryUUID = pszLibraryUUID ? CHString(pszLibraryUUID) : MOCreateUUID() ;
  142. pProvider->sProviderUUID = pszProviderUUID ? CHString(pszProviderUUID) : MOCreateUUID() ;
  143. pProvider->pPropSetList = NULL ;
  144. // Make sure there's a trailing backslash on the path specs
  145. //=========================================================
  146. if(pProvider->sOutputPath.Right(1) != _T("\\"))
  147. {
  148. pProvider->sOutputPath += _T("\\") ;
  149. }
  150. if(pProvider->sTLBPath.Right(1) != _T("\\"))
  151. {
  152. pProvider->sTLBPath += _T("\\") ;
  153. }
  154. // Type library path is quoted in source, so needs double backslashes
  155. //===================================================================
  156. DoubleBackslash(pProvider->sTLBPath) ;
  157. // Assemble output file names
  158. //===========================
  159. _stprintf(pProvider->szDEFFileSpec, _T("%s%s.DEF"),
  160. (LPCTSTR) pProvider->sOutputPath,
  161. (LPCTSTR) pProvider->sBaseName) ;
  162. // _stprintf(pProvider->szIDLFileSpec, _T("%s%s.IDL"),
  163. // (LPCTSTR) pProvider->sOutputPath,
  164. // (LPCTSTR) pProvider->sBaseName) ;
  165. _stprintf(pProvider->szMOFFileSpec, _T("%s%s.MOF"),
  166. (LPCTSTR) pProvider->sOutputPath,
  167. (LPCTSTR) pProvider->sBaseName) ;
  168. _stprintf(pProvider->szOLEFileSpec, _T("%sMAINDLL.CPP"),
  169. (LPCTSTR) pProvider->sOutputPath) ;
  170. _stprintf(pProvider->szMAKFileSpec, _T("%s%s.MAK"),
  171. (LPCTSTR) pProvider->sOutputPath,
  172. (LPCTSTR) pProvider->sBaseName) ;
  173. // Insert at end of provider list
  174. //===============================
  175. pTemp = (PROVIDER_INFO *) &pProviderList ;
  176. while(pTemp->pNext != NULL)
  177. {
  178. pTemp = pTemp->pNext ;
  179. }
  180. pProvider->pNext = NULL ;
  181. pTemp->pNext = pProvider ;
  182. return pProvider->dwProviderID ;
  183. }
  184. /*****************************************************************************
  185. *
  186. * FUNCTION : MOProviderCancel
  187. *
  188. * DESCRIPTION : Simply kills provider-in-progress
  189. *
  190. * INPUTS :
  191. *
  192. * OUTPUTS :
  193. *
  194. * RETURNS :
  195. *
  196. * COMMENTS :
  197. *
  198. *****************************************************************************/
  199. DllExport void MOProviderCancel(DWORD dwProviderID)
  200. {
  201. MOProviderDestroy(dwProviderID) ;
  202. }
  203. /*****************************************************************************
  204. *
  205. * FUNCTION : MOProviderClose
  206. *
  207. * DESCRIPTION : Terminates construction of a provider & writes files
  208. *
  209. * INPUTS : dwProviderID : ID of provider to commit
  210. * bForceFlag : If TRUE, existing files are overwritten
  211. * If FALSE, no files are created (provider
  212. * must still be closed or cancelled)
  213. *
  214. * OUTPUTS :
  215. *
  216. * RETURNS : MO_SUCCESS if successful, error code otherwise
  217. *
  218. * COMMENTS :
  219. *
  220. *****************************************************************************/
  221. DllExport DWORD MOProviderClose(DWORD dwProviderID, BOOL bForceFlag)
  222. {
  223. PROVIDER_INFO *pProvider ;
  224. PROPSET_INFO *pPropSet ;
  225. DWORD dwRetCode = MO_SUCCESS ;
  226. WCHAR szTemp[_MAX_PATH], *pSlash ;
  227. // Get the provider record
  228. //========================
  229. pProvider = GetProviderFromID(dwProviderID) ;
  230. if(pProvider == NULL)
  231. {
  232. dwLastError = MO_ERROR_PROVIDER_NOT_FOUND ;
  233. return MO_ERROR_PROVIDER_NOT_FOUND ;
  234. }
  235. // Check directory/file existence if force flag set
  236. //=================================================
  237. _tcscpy(szTemp, (LPCTSTR) pProvider->sOutputPath.Left(pProvider->sOutputPath.GetLength()-1)) ;
  238. if(!bForceFlag)
  239. {
  240. if(_taccess(szTemp, 0) == -1)
  241. {
  242. dwLastError = MO_ERROR_DIRECTORY_NOT_FOUND ;
  243. return MO_ERROR_DIRECTORY_NOT_FOUND ;
  244. }
  245. if(_taccess(pProvider->szDEFFileSpec, 0) != -1 ||
  246. // _taccess(pProvider->szIDLFileSpec, 0) != -1 ||
  247. _taccess(pProvider->szOLEFileSpec, 0) != -1)
  248. {
  249. dwLastError = MO_ERROR_FILES_EXIST ;
  250. return MO_ERROR_FILES_EXIST ;
  251. }
  252. // We need to traverse provider's property sets for file names
  253. //============================================================
  254. pPropSet = pProvider->pPropSetList ;
  255. while(pPropSet != NULL)
  256. {
  257. if(_taccess(pPropSet->szCPPFileSpec, 0) != -1 ||
  258. _taccess(pPropSet->szHFileSpec, 0) != -1)
  259. {
  260. dwLastError = MO_ERROR_FILES_EXIST ;
  261. return MO_ERROR_FILES_EXIST ;
  262. }
  263. pPropSet = pPropSet->pNext ;
  264. } // end while loop
  265. }
  266. // Create output directory if necessary
  267. //=====================================
  268. if(_taccess(szTemp, 0) == -1)
  269. {
  270. pSlash = szTemp ;
  271. for( ; ; )
  272. {
  273. pSlash = _tcschr(pSlash, _T('\\')) ;
  274. if(pSlash == NULL)
  275. {
  276. CreateDirectory(szTemp, NULL) ;
  277. break ;
  278. }
  279. if(*(pSlash-1) != _T(':'))
  280. {
  281. *pSlash = 0 ;
  282. CreateDirectory(szTemp, NULL) ;
  283. *pSlash = _T('\\') ;
  284. }
  285. pSlash++ ;
  286. }
  287. }
  288. if(_taccess(szTemp, 0) == -1)
  289. {
  290. dwLastError = MO_ERROR_DIRECTORY ;
  291. return MO_ERROR_DIRECTORY ;
  292. }
  293. pPropSet = pProvider->pPropSetList ;
  294. while(pPropSet != NULL)
  295. {
  296. pProvider->sObj += _T("\"$(OUTDIR)\\") + pPropSet->sBaseName + _T(".obj\" ");
  297. pProvider->sCpp += pPropSet->sBaseName + _T(".cpp ");
  298. pPropSet = pPropSet->pNext ;
  299. }
  300. // Create the output files
  301. //========================
  302. dwRetCode = CreateProviderFile(pProvider, NULL, pProvider->szDEFFileSpec, IDR_TEMPLATE_DEF) ;
  303. if (dwRetCode == MO_SUCCESS)
  304. dwRetCode = CreateProviderFile(pProvider, NULL, pProvider->szMOFFileSpec, IDR_TEMPLATE_MOF) ;
  305. // if (dwRetCode == MO_SUCCESS)
  306. // dwRetCode = CreateProviderFile(pProvider, NULL, pProvider->szIDLFileSpec, IDR_TEMPLATE_ODL) ;
  307. // if (dwRetCode == MO_SUCCESS)
  308. // dwRetCode = CreateProviderFile(pProvider, NULL, pProvider->szOLEFileSpec, IDR_TEMPLATE_OLE) ;
  309. if (dwRetCode == MO_SUCCESS)
  310. dwRetCode = CreateProviderFile(pProvider, pPropSet, pProvider->szMAKFileSpec, IDR_TEMPLATE_MAK) ;
  311. pPropSet = pProvider->pPropSetList ;
  312. while(pPropSet != NULL)
  313. {
  314. if (dwRetCode == MO_SUCCESS)
  315. dwRetCode = CreateProviderFile(pProvider, pPropSet, pPropSet->szCPPFileSpec, IDR_TEMPLATE_CPP) ;
  316. if (dwRetCode == MO_SUCCESS)
  317. dwRetCode = CreateProviderFile(pProvider, pPropSet, pPropSet->szHFileSpec, IDR_TEMPLATE_H) ;
  318. if (dwRetCode == MO_SUCCESS)
  319. dwRetCode = CreateProviderFile(pProvider, pPropSet, pProvider->szOLEFileSpec, IDR_TEMPLATE_DLL) ;
  320. pPropSet = pPropSet->pNext ;
  321. }
  322. // Delete all the associated records
  323. //==================================
  324. MOProviderDestroy(dwProviderID) ;
  325. return dwRetCode ;
  326. }
  327. /*****************************************************************************
  328. *
  329. * FUNCTION : MOPropSetOpen
  330. *
  331. * DESCRIPTION : Opens property set
  332. *
  333. * INPUTS :
  334. *
  335. * OUTPUTS :
  336. *
  337. * RETURNS :
  338. *
  339. * COMMENTS :
  340. *
  341. *****************************************************************************/
  342. DllExport DWORD MOPropSetOpen(DWORD dwProviderID,
  343. LPCWSTR pszBaseName,
  344. LPCWSTR pszDescription,
  345. LPCWSTR pszPropSetName,
  346. LPCWSTR pszPropSetUUID,
  347. LPCWSTR pszClassName,
  348. LPCWSTR pszParentClassName)
  349. {
  350. PROVIDER_INFO *pProvider ;
  351. PROPSET_INFO *pPropSet, *pTemp ;
  352. // Validate our input
  353. //===================
  354. if(!pszBaseName || !pszBaseName[0] ||
  355. !pszPropSetName || !pszPropSetName[0] ||
  356. !pszClassName || !pszClassName[0])
  357. {
  358. // As odd as this looks, it's what the ui is expecting.
  359. dwLastError = MO_ERROR_INVALID_PARAMETER ;
  360. return MO_INVALID_ID ;
  361. }
  362. // Locate the provider
  363. //====================
  364. pProvider = GetProviderFromID(dwProviderID) ;
  365. if(pProvider == NULL)
  366. {
  367. // As odd as this looks, it's what the ui is expecting.
  368. dwLastError = MO_ERROR_PROVIDER_NOT_FOUND ;
  369. return MO_INVALID_ID ;
  370. }
  371. // Create new property set record
  372. //===============================
  373. pPropSet = new PROPSET_INFO ;
  374. if(pPropSet == NULL)
  375. {
  376. // As odd as this looks, it's what the ui is expecting.
  377. dwLastError = MO_ERROR_MEMORY ;
  378. return MO_INVALID_ID ;
  379. }
  380. pPropSet->dwPropSetID = MONewPropSetID(pProvider) ;
  381. pPropSet->sBaseName = pszBaseName ;
  382. pPropSet->sDescription = pszDescription ? CHString(pszDescription) : _T("") ;
  383. pPropSet->sPropSetName = pszPropSetName ;
  384. pPropSet->sPropSetUUID = pszPropSetUUID && pszPropSetUUID[0] ? CHString(pszPropSetUUID) : MOCreateUUID() ;
  385. pPropSet->sClassName = pszClassName ;
  386. pPropSet->sParentClassName = pszParentClassName && pszParentClassName[0] ? CHString(pszParentClassName) : _T("Provider") ;
  387. pPropSet->pPropertyList = NULL ;
  388. pPropSet->pPropertyAttribList = NULL ;
  389. pPropSet->sBaseUpcase = pszBaseName ;
  390. pPropSet->sBaseUpcase.MakeUpper() ;
  391. // Create output file names
  392. //=========================
  393. _stprintf(pPropSet->szCPPFileSpec, _T("%s%s.CPP"),
  394. (LPCTSTR) pProvider->sOutputPath,
  395. (LPCTSTR) pPropSet->sBaseName) ;
  396. _stprintf(pPropSet->szHFileSpec, _T("%s%s.H"),
  397. (LPCTSTR) pProvider->sOutputPath,
  398. (LPCTSTR) pPropSet->sBaseName) ;
  399. // Add to the provider's list
  400. //===========================
  401. pTemp = (PROPSET_INFO *) &pProvider->pPropSetList ;
  402. while(pTemp->pNext != NULL)
  403. {
  404. pTemp = pTemp->pNext ;
  405. }
  406. pPropSet->pNext = NULL ;
  407. pTemp->pNext = pPropSet ;
  408. return pPropSet->dwPropSetID ;
  409. }
  410. /*****************************************************************************
  411. *
  412. * FUNCTION : MOPropertyAdd
  413. *
  414. * DESCRIPTION : Adds property to existing/open property set
  415. *
  416. * INPUTS :
  417. *
  418. * OUTPUTS :
  419. *
  420. * RETURNS : MO_SUCCESS or error code
  421. *
  422. * COMMENTS :
  423. *
  424. *****************************************************************************/
  425. DllExport DWORD MOPropertyAdd(DWORD dwProviderID,
  426. DWORD dwPropSetID,
  427. LPCWSTR pszProperty,
  428. LPCWSTR pszName,
  429. LPCWSTR pszPutMethod,
  430. LPCWSTR pszGetMethod,
  431. DWORD dwType,
  432. DWORD dwFlags)
  433. {
  434. PROVIDER_INFO *pProvider ;
  435. PROPSET_INFO *pPropSet ;
  436. PROPERTY_INFO *pProperty, *pTemp ;
  437. // Validate
  438. //=========
  439. if(!pszProperty || !pszProperty[0] ||
  440. !pszName || !pszName[0])
  441. {
  442. dwLastError = MO_ERROR_INVALID_PARAMETER ;
  443. return MO_ERROR_INVALID_PARAMETER ;
  444. }
  445. // Locate the provider
  446. //====================
  447. pProvider = GetProviderFromID(dwProviderID) ;
  448. if(pProvider == NULL)
  449. {
  450. dwLastError = MO_ERROR_PROVIDER_NOT_FOUND ;
  451. return MO_ERROR_PROVIDER_NOT_FOUND ;
  452. }
  453. // Locate the property set
  454. //========================
  455. pPropSet = GetPropSetFromID(pProvider, dwPropSetID) ;
  456. if(pProvider == NULL)
  457. {
  458. dwLastError = MO_ERROR_PROPSET_NOT_FOUND ;
  459. return MO_ERROR_PROPSET_NOT_FOUND ;
  460. }
  461. // Create new property record
  462. //===========================
  463. pProperty = new PROPERTY_INFO ;
  464. if(pProperty == NULL)
  465. {
  466. dwLastError = MO_ERROR_MEMORY ;
  467. return MO_ERROR_MEMORY ;
  468. }
  469. pProperty->sProperty = pszProperty ;
  470. pProperty->sName = pszName ;
  471. pProperty->sPutMethod = pszPutMethod && pszPutMethod[0] ? CHString(pszPutMethod) : _T("NULL") ;
  472. pProperty->sGetMethod = pszGetMethod && pszGetMethod[0] ? CHString(pszGetMethod) : _T("NULL") ;
  473. pProperty->dwType = dwType ;
  474. pProperty->dwFlags = dwFlags ;
  475. // Create property name pointer
  476. //=============================
  477. pProperty->sPropertyNamePtr.Format(L"p%s", pszProperty);
  478. // Add to the property set
  479. //========================
  480. pTemp = (PROPERTY_INFO *) &pPropSet->pPropertyList ;
  481. while(pTemp->pNext != NULL)
  482. {
  483. pTemp = pTemp->pNext ;
  484. }
  485. pProperty->pNext = NULL ;
  486. pTemp->pNext = pProperty ;
  487. return MO_SUCCESS ;
  488. }
  489. /*****************************************************************************
  490. *
  491. * FUNCTION : MOPropertyAttribSet
  492. *
  493. * DESCRIPTION : Allows user to assign attributes to properties at run-time
  494. *
  495. * INPUTS :
  496. *
  497. * OUTPUTS :
  498. *
  499. * RETURNS :
  500. *
  501. * COMMENTS :
  502. *
  503. *****************************************************************************/
  504. DllExport DWORD MOPropertyAttribSet(DWORD dwProviderID,
  505. DWORD dwPropSetID,
  506. LPCWSTR pszProperty,
  507. DWORD dwFlags)
  508. {
  509. PROVIDER_INFO *pProvider ;
  510. PROPSET_INFO *pPropSet ;
  511. PROPERTY_ATTRIB_INFO *pPropAttrib ;
  512. // Validate
  513. //=========
  514. if(!pszProperty || !pszProperty[0])
  515. {
  516. dwLastError = MO_ERROR_INVALID_PARAMETER ;
  517. return MO_ERROR_INVALID_PARAMETER ;
  518. }
  519. // Locate the provider
  520. //====================
  521. pProvider = GetProviderFromID(dwProviderID) ;
  522. if(pProvider == NULL)
  523. {
  524. dwLastError = MO_ERROR_PROVIDER_NOT_FOUND ;
  525. return MO_ERROR_PROVIDER_NOT_FOUND ;
  526. }
  527. // Locate the property set
  528. //========================
  529. pPropSet = GetPropSetFromID(pProvider, dwPropSetID) ;
  530. if(pProvider == NULL)
  531. {
  532. dwLastError = MO_ERROR_PROPSET_NOT_FOUND ;
  533. return MO_ERROR_PROPSET_NOT_FOUND ;
  534. }
  535. // Create new record for property
  536. //===============================
  537. pPropAttrib = new PROPERTY_ATTRIB_INFO ;
  538. if(pPropAttrib == NULL)
  539. {
  540. dwLastError = MO_ERROR_MEMORY ;
  541. return MO_ERROR_MEMORY ;
  542. }
  543. pPropAttrib->sProperty = pszProperty ;
  544. pPropAttrib->dwFlags = dwFlags ;
  545. pPropAttrib->pNext = pPropSet->pPropertyAttribList ;
  546. pPropSet->pPropertyAttribList = pPropAttrib ;
  547. return MO_SUCCESS ;
  548. }
  549. /*****************************************************************************
  550. *
  551. * FUNCTION : MOGetLastError
  552. *
  553. * DESCRIPTION : Retrieves error code
  554. *
  555. * INPUTS :
  556. *
  557. * OUTPUTS :
  558. *
  559. * RETURNS : Numeric code of last error encountered
  560. *
  561. * COMMENTS :
  562. *
  563. *****************************************************************************/
  564. DllExport DWORD MOGetLastError(void)
  565. {
  566. return dwLastError ;
  567. }
  568. /*****************************************************************************
  569. *
  570. * FUNCTION : MOPropertyAttribSet
  571. *
  572. * DESCRIPTION : Allows user to assign attributes to properties at run-time
  573. *
  574. * INPUTS :
  575. *
  576. * OUTPUTS :
  577. *
  578. * RETURNS :
  579. *
  580. * COMMENTS :
  581. *
  582. *****************************************************************************/
  583. DllExport void MOResetLastError(void)
  584. {
  585. dwLastError = MO_SUCCESS ;
  586. }
  587. //=============================================================================
  588. //=============================================================================
  589. //
  590. //
  591. // UTILITY ROUTINES
  592. //
  593. //
  594. //=============================================================================
  595. //=============================================================================
  596. /*****************************************************************************
  597. *
  598. * FUNCTION : MONewProviderID
  599. *
  600. * DESCRIPTION : Generates ID unique among open providers
  601. *
  602. * INPUTS : nothing
  603. *
  604. * OUTPUTS : nothing
  605. *
  606. * RETURNS : Unique ID
  607. *
  608. * COMMENTS : No error returned
  609. *
  610. *****************************************************************************/
  611. DWORD MONewProviderID()
  612. {
  613. static DWORD dwNextID = MO_INVALID_ID ;
  614. while(++dwNextID == MO_INVALID_ID || GetProviderFromID(dwNextID) != NULL) ;
  615. return dwNextID ;
  616. }
  617. /*****************************************************************************
  618. *
  619. * FUNCTION : MONewPropSetID
  620. *
  621. * DESCRIPTION : Generates ID unique among open properties
  622. *
  623. * INPUTS : nothing
  624. *
  625. * OUTPUTS : nothing
  626. *
  627. * RETURNS : Unique ID
  628. *
  629. * COMMENTS : No error returned
  630. *
  631. *****************************************************************************/
  632. DWORD MONewPropSetID(PROVIDER_INFO *pProvider)
  633. {
  634. static DWORD dwNextID = MO_INVALID_ID ;
  635. while(++dwNextID == MO_INVALID_ID || GetPropSetFromID(pProvider, dwNextID) != NULL) ;
  636. return dwNextID ;
  637. }
  638. /*****************************************************************************
  639. *
  640. * FUNCTION : GetProviderFromID
  641. *
  642. * DESCRIPTION : Lookup function for open providers
  643. *
  644. * INPUTS : ID of desired provider
  645. *
  646. * OUTPUTS : none
  647. *
  648. * RETURNS : Pointer to provider record if found, NULL if not
  649. *
  650. * COMMENTS :
  651. *
  652. *****************************************************************************/
  653. PROVIDER_INFO *GetProviderFromID(DWORD dwProviderID)
  654. {
  655. PROVIDER_INFO *pProvider ;
  656. pProvider = pProviderList ;
  657. while(pProvider != NULL)
  658. {
  659. if(pProvider->dwProviderID == dwProviderID)
  660. {
  661. break ;
  662. }
  663. pProvider = pProvider->pNext ;
  664. }
  665. return pProvider ;
  666. }
  667. /*****************************************************************************
  668. *
  669. * FUNCTION : GetPropSetFromID
  670. *
  671. * DESCRIPTION : Lookup function for open property sets
  672. *
  673. * INPUTS : ID of desired property set
  674. *
  675. * OUTPUTS : none
  676. *
  677. * RETURNS : Pointer to provider record if found, NULL if not
  678. *
  679. * COMMENTS :
  680. *
  681. *****************************************************************************/
  682. PROPSET_INFO *GetPropSetFromID(PROVIDER_INFO *pProvider, DWORD dwPropSetID)
  683. {
  684. PROPSET_INFO *pPropSet ;
  685. pPropSet = pProvider->pPropSetList ;
  686. while(pPropSet != NULL)
  687. {
  688. if(pPropSet->dwPropSetID == dwPropSetID)
  689. {
  690. break ;
  691. }
  692. pPropSet = pPropSet->pNext ;
  693. }
  694. return pPropSet ;
  695. }
  696. /*****************************************************************************
  697. *
  698. * FUNCTION : MOProviderDestroy
  699. *
  700. * DESCRIPTION : Destroys all structs associated with a provider
  701. *
  702. * INPUTS :
  703. *
  704. * OUTPUTS :
  705. *
  706. * RETURNS : MO_SUCCESS or error code
  707. *
  708. * COMMENTS :
  709. *
  710. *****************************************************************************/
  711. DWORD MOProviderDestroy(DWORD dwProviderID)
  712. {
  713. PROVIDER_INFO *pProvider, *pPredecessor ;
  714. PROPSET_INFO *pPropSet ;
  715. PROPERTY_INFO *pProperty ;
  716. PROPERTY_ATTRIB_INFO *pPropAttrib ;
  717. // Locate the provider record & remove from list
  718. //==============================================
  719. pProvider = pProviderList ;
  720. pPredecessor = (PROVIDER_INFO *) &pProviderList ;
  721. while(pProvider != NULL)
  722. {
  723. if(pProvider->dwProviderID == dwProviderID)
  724. {
  725. pPredecessor->pNext = pProvider->pNext ;
  726. break ;
  727. }
  728. pPredecessor = pProvider ;
  729. pProvider = pProvider->pNext ;
  730. }
  731. // Was the provider record found?
  732. //===============================
  733. if(pProvider == NULL)
  734. {
  735. return MO_ERROR_PROVIDER_NOT_FOUND ;
  736. }
  737. // Yep -- destroy everything
  738. //==========================
  739. while(pProvider->pPropSetList != NULL)
  740. {
  741. pPropSet = pProvider->pPropSetList ;
  742. pProvider->pPropSetList = pPropSet->pNext ;
  743. while(pPropSet->pPropertyList != NULL)
  744. {
  745. pProperty = pPropSet->pPropertyList ;
  746. pPropSet->pPropertyList = pProperty->pNext ;
  747. delete pProperty ;
  748. }
  749. while(pPropSet->pPropertyAttribList != NULL)
  750. {
  751. pPropAttrib = pPropSet->pPropertyAttribList ;
  752. pPropSet->pPropertyAttribList = pPropAttrib->pNext ;
  753. delete pPropAttrib ;
  754. }
  755. delete pPropSet ;
  756. }
  757. delete pProvider ;
  758. return MO_SUCCESS ;
  759. }
  760. /*****************************************************************************
  761. *
  762. * FUNCTION : MOCreateUUID
  763. *
  764. * DESCRIPTION :
  765. *
  766. * INPUTS :
  767. *
  768. * OUTPUTS :
  769. *
  770. * RETURNS :
  771. *
  772. * COMMENTS :
  773. *
  774. *****************************************************************************/
  775. WCHAR *MOCreateUUID(void)
  776. {
  777. static WCHAR szUUID[50] ;
  778. UUID RawUUID ;
  779. WCHAR *pszSysUUID ;
  780. // Make sure we don't return anything twice
  781. //=========================================
  782. _tcscpy(szUUID, _T("Unable to create UUID")) ;
  783. // Generate the new UUID
  784. //======================
  785. if(UuidCreate(&RawUUID) == RPC_S_OK && UuidToString(&RawUUID, &pszSysUUID) == RPC_S_OK)
  786. {
  787. _tcscpy(szUUID, (LPCWSTR) pszSysUUID) ;
  788. RpcStringFree(&pszSysUUID) ;
  789. }
  790. return szUUID ;
  791. }
  792. /*****************************************************************************
  793. *
  794. * FUNCTION : CreateProviderFile
  795. *
  796. * DESCRIPTION :
  797. *
  798. * INPUTS :
  799. *
  800. * OUTPUTS :
  801. *
  802. * RETURNS :
  803. *
  804. * COMMENTS :
  805. *
  806. *****************************************************************************/
  807. DWORD CreateProviderFile(PROVIDER_INFO *pProvider,
  808. PROPSET_INFO *pPropSet,
  809. LPCWSTR pszFileSpec,
  810. DWORD dwTemplateID)
  811. {
  812. CHString sTemp, sTemp2, sOutput ;
  813. int iIndex ;
  814. WCHAR cDesignator ;
  815. HRSRC hResHandle ;
  816. HGLOBAL hTemplateHandle ;
  817. char *pFrom, *pTo ;
  818. DWORD dwBufferSize ;
  819. // Locate/load template file as resource
  820. //======================================
  821. hResHandle = FindResource(hOurAFXResourceHandle, (LPCTSTR)(DWORD_PTR) dwTemplateID, _T("BINARY")) ;
  822. if(hResHandle == NULL)
  823. {
  824. return MO_ERROR_TEMPLATE_NOT_FOUND ;
  825. }
  826. hTemplateHandle = LoadResource(hOurAFXResourceHandle, hResHandle) ;
  827. if(hTemplateHandle == NULL)
  828. {
  829. return MO_ERROR_TEMPLATE_NOT_FOUND ;
  830. }
  831. // Put the resource into a CHString & find the closing
  832. // tilde string (~~~~~~) to place the terminating NULL
  833. // (the resource doesn't have the NULL in it...) MS is
  834. // supposedly considering making SizeofResource()
  835. // actually return the proper size of the resource, but
  836. // for now it only returns rounded up to the next alignment.
  837. //==========================================================
  838. dwBufferSize = SizeofResource(hOurAFXResourceHandle, hResHandle) ;
  839. if(dwBufferSize == 0)
  840. {
  841. return MO_ERROR_TEMPLATE_NOT_FOUND ;
  842. }
  843. pFrom = (char *) LockResource(hTemplateHandle) ;
  844. if(pFrom == NULL)
  845. {
  846. return MO_ERROR_MEMORY ;
  847. }
  848. pTo = new char[dwBufferSize];
  849. if(pTo == NULL)
  850. {
  851. return MO_ERROR_MEMORY ;
  852. }
  853. memcpy(pTo, pFrom, dwBufferSize) ;
  854. pFrom = strstr(pTo, "~~~~~~") ;
  855. if(pFrom == NULL)
  856. {
  857. delete []pTo;
  858. return MO_ERROR_TEMPLATE_NOT_FOUND ;
  859. }
  860. *pFrom = 0 ;
  861. sTemp = pTo;
  862. delete []pTo;
  863. // Perform string substitutions
  864. //=============================
  865. sOutput = _T("") ;
  866. iIndex = sTemp.Find(_T("%%")) ;
  867. while(iIndex != -1)
  868. {
  869. cDesignator = sTemp.GetAt(iIndex + 2) ;
  870. if (_T('8') == cDesignator)
  871. {
  872. // check to see if the string in pPropSet->sDescription
  873. // is valid. i.e. no carriage returns.
  874. CHString chsCompString = pPropSet->sDescription;
  875. LONG len = chsCompString.GetLength();
  876. if (len)
  877. {
  878. for (int i = 0;i<len ;i++ )
  879. {
  880. if ((_T('\n') == chsCompString[i]) || (_T('\r') == chsCompString[i]))
  881. {
  882. chsCompString.SetAt(i, _T(' '));
  883. } // end if
  884. } // end for
  885. pPropSet->sDescription = chsCompString.GetBuffer(0);
  886. } // end if
  887. } // end if
  888. sOutput += sTemp.Left(iIndex) ;
  889. sTemp = sTemp.Right(sTemp.GetLength() - iIndex - 3) ;
  890. switch (cDesignator)
  891. {
  892. case _T('1'):
  893. sOutput += pProvider->sBaseName;
  894. break;
  895. case _T('2'):
  896. sOutput += pProvider->sDescription;
  897. break;
  898. case _T('3'):
  899. sOutput += pProvider->sTLBPath;
  900. break;
  901. case _T('4'):
  902. sOutput += pProvider->sLibraryUUID;
  903. break;
  904. case _T('5'):
  905. sOutput += pProvider->sProviderUUID;
  906. break;
  907. case _T('6'):
  908. sOutput += sSystemDirectory;
  909. break;
  910. case _T('7'):
  911. sOutput += pPropSet == NULL ? _T("") : pPropSet->sBaseName;
  912. break;
  913. case _T('8'):
  914. sOutput += pPropSet == NULL ? _T("") : pPropSet->sDescription;
  915. break;
  916. case _T('9'):
  917. sOutput += pPropSet == NULL ? _T("") : pPropSet->sPropSetName;
  918. break;
  919. case _T('A'):
  920. sOutput += pPropSet == NULL ? _T("") : pPropSet->sPropSetUUID;
  921. break;
  922. case _T('B'):
  923. sOutput += pPropSet == NULL ? _T("") : pPropSet->sClassName;
  924. break;
  925. case _T('C'):
  926. sOutput += pPropSet == NULL ? _T("") : pPropSet->sParentClassName;
  927. break;
  928. case _T('D'):
  929. sOutput +=pPropSet == NULL ? _T("") : GetPropNameDefs(pPropSet);
  930. break;
  931. // case _T('E'):
  932. // sOutput += pPropSet == NULL ? _T("") : GetPropEnums(pPropSet);
  933. // break;
  934. case _T('F'):
  935. sOutput += pPropSet == NULL ? _T("") : GetPropNameExterns(pPropSet);
  936. break;
  937. // case _T('G'):
  938. // sOutput += pPropSet == NULL ? _T("") : GetPropTemplates(pPropSet);
  939. // break;
  940. case _T('H'):
  941. sOutput += pPropSet == NULL ? _T("") : GetPropPuts(pPropSet);
  942. break;
  943. // cDesignator == _T('I') ? pPropSet == NULL ? _T("") : GetPropGets(pPropSet);
  944. case _T('J'):
  945. sOutput += pPropSet == NULL ? _T("") : pPropSet->sBaseUpcase;
  946. break;
  947. // case _T('K'):
  948. // sOutput += pPropSet == NULL ? _T("") : GetPropertyAttribs(pPropSet);
  949. // break;
  950. case _T('L'):
  951. sOutput += pProvider->sCpp;
  952. break;
  953. case _T('M'):
  954. sOutput += pProvider->sObj;
  955. break;
  956. default:
  957. // CHString(_T("")) ;
  958. break;
  959. }
  960. iIndex = sTemp.Find(_T("%%")) ;
  961. }
  962. sOutput += sTemp ;
  963. // Write the output file
  964. //======================
  965. FILE *fOutFile = NULL;
  966. fOutFile = _tfopen(pszFileSpec, _T("wb"));
  967. if (fOutFile == NULL)
  968. {
  969. return MO_ERROR_FILE_OPEN ;
  970. }
  971. _bstr_t ToAnsi(sOutput);
  972. char *pAnsi = (char *)ToAnsi;
  973. if (fwrite(pAnsi, strlen(pAnsi), 1, fOutFile) != 1)
  974. {
  975. fclose(fOutFile);
  976. return MO_ERROR_FILE_WRITE_ERROR;
  977. }
  978. fclose(fOutFile);
  979. return MO_SUCCESS ;
  980. }
  981. /*****************************************************************************
  982. *
  983. * FUNCTION : MODoubleBackslash
  984. *
  985. * DESCRIPTION : Converts single backslashes to double backslashes
  986. *
  987. * INPUTS :
  988. *
  989. * OUTPUTS :
  990. *
  991. * RETURNS :
  992. *
  993. * COMMENTS :
  994. *
  995. *****************************************************************************/
  996. void DoubleBackslash(CHString &sTarget)
  997. {
  998. WCHAR szTemp[_MAX_PATH] = {0};
  999. // Convert to string for easier manipulation
  1000. //==========================================
  1001. _tcscpy(szTemp, (LPCWSTR) sTarget) ;
  1002. sTarget = _T("") ;
  1003. WCHAR *pToken = _tcstok(szTemp, _T("\\")) ;
  1004. while(pToken != NULL)
  1005. {
  1006. sTarget += pToken ;
  1007. sTarget += _T("\\\\") ;
  1008. pToken = _tcstok(NULL, _T("\\")) ;
  1009. }
  1010. }
  1011. /*****************************************************************************
  1012. *
  1013. * FUNCTION : GetPropNameDefs
  1014. *
  1015. * DESCRIPTION : Returns CHString containing property set name definitions
  1016. *
  1017. * INPUTS :
  1018. *
  1019. * OUTPUTS :
  1020. *
  1021. * RETURNS :
  1022. *
  1023. * COMMENTS :
  1024. *
  1025. *****************************************************************************/
  1026. CHString GetPropNameDefs(PROPSET_INFO *pPropSet)
  1027. {
  1028. PROPERTY_INFO *pProperty ;
  1029. WCHAR szTemp[_MAX_PATH] ;
  1030. CHString sTemp;
  1031. if(pPropSet != NULL)
  1032. {
  1033. pProperty = pPropSet->pPropertyList ;
  1034. while(pProperty != NULL)
  1035. {
  1036. _stprintf(szTemp, _T("const static WCHAR* %s = L\"%s\" ;\r\n"),
  1037. (LPCWSTR) pProperty->sPropertyNamePtr,
  1038. (LPCWSTR) pProperty->sName) ;
  1039. sTemp += szTemp ;
  1040. pProperty = pProperty->pNext ;
  1041. }
  1042. }
  1043. return sTemp ;
  1044. }
  1045. /*****************************************************************************
  1046. *
  1047. * FUNCTION : GetPropEnums
  1048. *
  1049. * DESCRIPTION : Returns CHString containing property TPROP declarations
  1050. *
  1051. * INPUTS :
  1052. *
  1053. * OUTPUTS :
  1054. *
  1055. * RETURNS :
  1056. *
  1057. * COMMENTS :
  1058. *
  1059. *****************************************************************************/
  1060. //CHString GetPropEnums(PROPSET_INFO *pPropSet)
  1061. //{
  1062. // PROPERTY_INFO *pProperty ;
  1063. // WCHAR szTemp[_MAX_PATH] ;
  1064. //
  1065. // CHString sTemp;
  1066. //
  1067. // if(pPropSet != NULL)
  1068. // {
  1069. // pProperty = pPropSet->pPropertyList ;
  1070. // while(pProperty != NULL)
  1071. // {
  1072. // if(sTemp.IsEmpty())
  1073. // {
  1074. // sTemp = _T(":") ;
  1075. // }
  1076. // else
  1077. // {
  1078. // _stprintf(szTemp, _T(",\r\n%*s"), pPropSet->sClassName.GetLength() * 2 + 5, _T("")) ;
  1079. // sTemp += szTemp ;
  1080. // }
  1081. //
  1082. // _stprintf(szTemp, _T("TPROP(%s)"), (const WCHAR *) pProperty->sProperty) ;
  1083. //
  1084. // sTemp += szTemp ;
  1085. //
  1086. // pProperty = pProperty->pNext ;
  1087. // }
  1088. // }
  1089. //
  1090. // return sTemp ;
  1091. //}
  1092. /*****************************************************************************
  1093. *
  1094. * FUNCTION : GetPropNameExterns
  1095. *
  1096. * DESCRIPTION : Returns CHString containing property name external declarations
  1097. *
  1098. * INPUTS :
  1099. *
  1100. * OUTPUTS :
  1101. *
  1102. * RETURNS :
  1103. *
  1104. * COMMENTS :
  1105. *
  1106. *****************************************************************************/
  1107. CHString GetPropNameExterns(PROPSET_INFO *pPropSet)
  1108. {
  1109. PROPERTY_INFO *pProperty ;
  1110. WCHAR szTemp[_MAX_PATH] ;
  1111. CHString sTemp ;
  1112. if(pPropSet != NULL)
  1113. {
  1114. pProperty = pPropSet->pPropertyList ;
  1115. while(pProperty != NULL)
  1116. {
  1117. _stprintf(szTemp, _T("extern const WCHAR* %s ;\r\n"), LPCTSTR(pProperty->sPropertyNamePtr)) ;
  1118. sTemp += szTemp ;
  1119. pProperty = pProperty->pNext ;
  1120. }
  1121. }
  1122. return sTemp ;
  1123. }
  1124. /*****************************************************************************
  1125. *
  1126. * FUNCTION : GetPropTemplates
  1127. *
  1128. * DESCRIPTION : Returns CHString containing property template declarations
  1129. *
  1130. * INPUTS :
  1131. *
  1132. * OUTPUTS :
  1133. *
  1134. * RETURNS :
  1135. *
  1136. * COMMENTS :
  1137. *
  1138. *****************************************************************************/
  1139. //CHString GetPropTemplates(PROPSET_INFO *pPropSet)
  1140. //{
  1141. // PROPERTY_INFO *pProperty ;
  1142. // WCHAR szTemp[_MAX_PATH] ;
  1143. // CHString sPropAttribs ;
  1144. //
  1145. // CHString sTemp ;
  1146. //
  1147. // if(pPropSet != NULL)
  1148. // {
  1149. // pProperty = pPropSet->pPropertyList ;
  1150. // while(pProperty != NULL)
  1151. // {
  1152. // // This is easier if we construct the property section separately
  1153. // //===============================================================
  1154. //
  1155. // sPropAttribs = BuildPropAttribString(pProperty->dwFlags) ;
  1156. //
  1157. // _stprintf(szTemp, _T(" MOProperty <%s, %s, %s, %s, %s> %s ;\r\n"),
  1158. // pProperty->dwType == MO_PROPTYPE_DWORD ? _T("DWORD") :
  1159. // pProperty->dwType == MO_PROPTYPE_CHString ? _T("CHString") :
  1160. // pProperty->dwType == MO_PROPTYPE_BOOL ? _T("bool") :
  1161. // pProperty->dwType == MO_PROPTYPE_DATETIME ? _T("WBEMTime") : _T("Variant"),
  1162. // (const WCHAR *) pProperty->sPropertyNamePtr,
  1163. // (const WCHAR *) sPropAttribs,
  1164. // (const WCHAR *) pProperty->sPutMethod,
  1165. // (const WCHAR *) pProperty->sGetMethod,
  1166. // (const WCHAR *) pProperty->sProperty) ;
  1167. //
  1168. // sTemp += szTemp ;
  1169. //
  1170. // pProperty = pProperty->pNext ;
  1171. // }
  1172. // }
  1173. //
  1174. // return sTemp ;
  1175. //}
  1176. /*****************************************************************************
  1177. *
  1178. * FUNCTION : GetPropertyAttribs
  1179. *
  1180. * DESCRIPTION : Returns CHString containing run-time property attribute
  1181. * assignments
  1182. *
  1183. * INPUTS :
  1184. *
  1185. * OUTPUTS :
  1186. *
  1187. * RETURNS :
  1188. *
  1189. * COMMENTS :
  1190. *
  1191. *****************************************************************************/
  1192. //CHString GetPropertyAttribs(PROPSET_INFO *pPropSet)
  1193. //{
  1194. // PROPERTY_ATTRIB_INFO *pPropAttrib ;
  1195. // WCHAR szTemp[_MAX_PATH] ;
  1196. // CHString sPropAttribs ;
  1197. //
  1198. // CHString sTemp ;
  1199. //
  1200. // if(pPropSet != NULL)
  1201. // {
  1202. // pPropAttrib = pPropSet->pPropertyAttribList ;
  1203. // while(pPropAttrib != NULL)
  1204. // {
  1205. // sPropAttribs = BuildPropAttribString(pPropAttrib->dwFlags) ;
  1206. // _stprintf(szTemp, _T(" %s.SetAttributes(%s) ;\r\n"),
  1207. // (const WCHAR *) pPropAttrib->sProperty,
  1208. // (const WCHAR *) sPropAttribs) ;
  1209. //
  1210. // sTemp += szTemp ;
  1211. //
  1212. // pPropAttrib = pPropAttrib->pNext ;
  1213. // }
  1214. // }
  1215. //
  1216. // return sTemp ;
  1217. //}
  1218. /*****************************************************************************
  1219. *
  1220. * FUNCTION : BuildPropAttribString
  1221. *
  1222. * DESCRIPTION : Constructs textual representation of property attributes
  1223. *
  1224. * INPUTS :
  1225. *
  1226. * OUTPUTS :
  1227. *
  1228. * RETURNS :
  1229. *
  1230. * COMMENTS :
  1231. *
  1232. *****************************************************************************/
  1233. //CHString BuildPropAttribString (DWORD dwFlags)
  1234. //{
  1235. // CHString sAttribs ;
  1236. //
  1237. // if(dwFlags & MO_ATTRIB_READ)
  1238. // {
  1239. // if(!sAttribs.IsEmpty())
  1240. // {
  1241. // sAttribs += _T(" | ") ;
  1242. // }
  1243. // sAttribs += _T("PROPERTY_READABLE") ;
  1244. // }
  1245. //
  1246. // if(dwFlags & MO_ATTRIB_WRITE)
  1247. // {
  1248. // if(!sAttribs.IsEmpty())
  1249. // {
  1250. // sAttribs += _T(" | ") ;
  1251. // }
  1252. // sAttribs += _T("PROPERTY_WRITEABLE") ;
  1253. // }
  1254. //
  1255. // if(dwFlags & MO_ATTRIB_VOLATILE)
  1256. // {
  1257. // if(!sAttribs.IsEmpty())
  1258. // {
  1259. // sAttribs += _T(" | ") ;
  1260. // }
  1261. // sAttribs += _T("PROPERTY_VOLATILE") ;
  1262. // }
  1263. //
  1264. // if(dwFlags & MO_ATTRIB_EXPENSIVE)
  1265. // {
  1266. // if(!sAttribs.IsEmpty())
  1267. // {
  1268. // sAttribs += _T(" | ") ;
  1269. // }
  1270. // sAttribs += _T("PROPERTY_EXPENSIVE") ;
  1271. // }
  1272. //
  1273. // if(dwFlags & MO_ATTRIB_KEY)
  1274. // {
  1275. // if(!sAttribs.IsEmpty())
  1276. // {
  1277. // sAttribs += _T(" | ") ;
  1278. // }
  1279. // sAttribs += _T("PROPERTY_KEY") ;
  1280. // }
  1281. //
  1282. // if(sAttribs.IsEmpty())
  1283. // {
  1284. // sAttribs = _T("0") ;
  1285. // }
  1286. //
  1287. // return sAttribs ;
  1288. //}
  1289. /*****************************************************************************
  1290. *
  1291. * FUNCTION : GetPropPuts
  1292. *
  1293. * DESCRIPTION : Returns CHString containing run-time property attribute
  1294. * assignments
  1295. *
  1296. * INPUTS :
  1297. *
  1298. * OUTPUTS :
  1299. *
  1300. * RETURNS :
  1301. *
  1302. * COMMENTS :
  1303. *
  1304. *****************************************************************************/
  1305. CHString GetPropPuts (PROPSET_INFO *pPropSet)
  1306. {
  1307. WCHAR szTemp[_MAX_PATH] ;
  1308. CHString sPutType;
  1309. PPROPERTY_INFO pProperty = NULL;
  1310. CHString sTemp = _T("");
  1311. if (NULL != pPropSet)
  1312. {
  1313. pProperty = pPropSet->pPropertyList;
  1314. while (NULL != pProperty)
  1315. {
  1316. _stprintf(szTemp, _T("// pInstance->Set%s(%s, <Property Value>);\r\n"),
  1317. pProperty->dwType == MO_PROPTYPE_DWORD ? _T("DWORD") :
  1318. pProperty->dwType == MO_PROPTYPE_CHString ? _T("CHString") :
  1319. pProperty->dwType == MO_PROPTYPE_BOOL ? _T("bool") :
  1320. pProperty->dwType == MO_PROPTYPE_DATETIME ? _T("WBEMTime") :
  1321. _T("Variant"),
  1322. (LPCTSTR)pProperty->sPropertyNamePtr);
  1323. sTemp += szTemp ;
  1324. pProperty = pProperty->pNext;
  1325. }
  1326. }
  1327. return sTemp;
  1328. }