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.

1149 lines
29 KiB

  1. /*
  2. Related Files:
  3. [Section = Compile]
  4. %OsUtilDir%:OsUtil.hxx
  5. [Section =End]
  6. */
  7. /* -------------------------------------------------------------------------
  8. Project : OB - Type Information Interface
  9. Platform : Win32
  10. Module : osutil.cpp
  11. Copyright (C) 1992-3, Microsoft Corporation
  12. ---------------------------------------------------------------------------
  13. Notes : Library routines for programs that run under Win32
  14. ---------------------------------------------------------------------------
  15. Revision History:
  16. [ 0] 09-Mar-1993 Angelach: Created Test
  17. [ 1] 10-Mar-1993 Angelach: added support to Win32s
  18. [ 2] 06-Jul-1994 Angelach: added support for remoting
  19. typelib testing
  20. [ 3] 27-Oct-1994 Angelach: added LCMapStringX
  21. [ 4] 06-Mar-1995 Angelach: added osGetNetDrive
  22. [ 5] 07-Mar-1995 Angelach: added Memory-leak detection
  23. --------------------------------------------------------------------------- */
  24. #include "osutil32.hxx"
  25. IMalloc FAR* ppmalloc ; // need for memory allocation
  26. IMallocSpy FAR* g_IMallocSpy ; // [7]
  27. /*---------------------------------------------------------------------------
  28. NAME : osAllocSpaces
  29. PURPOSE : obtains some spaces from the far heap
  30. INPUTS : nSize - no of bytes to be allocated
  31. OUTPUT : pointer to the allocated space
  32. NOTES : caller is responsible to free up the memory after used
  33. ---------------------------------------------------------------------------*/
  34. VOID FAR * osAllocSpaces(WORD nSize)
  35. {
  36. return ( (VOID FAR *)malloc(nSize) ) ;
  37. }
  38. /*---------------------------------------------------------------------------
  39. NAME : osGetRootDir
  40. PURPOSE : Retrieves pathspec of the root directory
  41. INPUTS : lpszRootDir - storage for the pathspec
  42. OUTPUT : none
  43. NOTES :
  44. ---------------------------------------------------------------------------*/
  45. VOID FAR osGetRootDir(LPXSTR lpszRootDir)
  46. {
  47. osStrCpy(lpszRootDir, XSTR("c:")) ;
  48. osStrCat(lpszRootDir, szPathSep) ;
  49. }
  50. /*---------------------------------------------------------------------------
  51. NAME : osGetCurDir
  52. PURPOSE : Retrieves pathspec of the current directory
  53. INPUTS : lpszCurDir - storage for the pathspec
  54. OUTPUT : True if information is retrieved successfully; otherwise, False
  55. lpszCurDir contains the pathspec if True
  56. NOTES :
  57. ---------------------------------------------------------------------------*/
  58. BOOL FAR osGetCurDir(LPXSTR lpszCurDir)
  59. {
  60. int i ;
  61. #if defined (OAU) && !defined (UNICODE) // [1]
  62. char szBufferC[256];
  63. i = GetCurrentDirectory((DWORD)256, szBufferC) ;
  64. MultiByteToWideChar(CP_ACP,
  65. MB_PRECOMPOSED,
  66. szBufferC,
  67. -1,
  68. lpszCurDir,
  69. 256);
  70. #else // if OAU && ! UNICODE
  71. i = GetCurrentDirectory((DWORD)256, lpszCurDir) ;
  72. #endif // if OAU && ! UNICODE
  73. if ( i != 0 )
  74. return TRUE ; // info of the current directory
  75. else // is retrieved successfully
  76. return FALSE ;
  77. }
  78. /*---------------------------------------------------------------------------
  79. NAME : osMkDir
  80. PURPOSE : Creates a subdirectory
  81. INPUTS : lpszSubDir - name of the subdirectory to be created
  82. OUTPUT : True if subdirectory is created successfully; otherwise, False
  83. NOTES :
  84. ---------------------------------------------------------------------------*/
  85. BOOL FAR osMkDir(LPXSTR lpszSubDir)
  86. {
  87. SECURITY_ATTRIBUTES sa ;
  88. BOOL rCode ;
  89. sa.nLength = sizeof(SECURITY_ATTRIBUTES) ;
  90. sa.lpSecurityDescriptor = NULL ;
  91. sa.bInheritHandle = FALSE ;
  92. #if defined (OAU) && !defined (UNICODE) // [1]
  93. char szBufferS[256];
  94. WideCharToMultiByte(CP_ACP,
  95. 0,
  96. lpszSubDir,
  97. -1,
  98. szBufferS,
  99. 256,
  100. NULL,
  101. NULL);
  102. rCode = CreateDirectory(szBufferS, &sa) ;
  103. #else // if OAU && ! UNICODE
  104. rCode = CreateDirectory(lpszSubDir, &sa) ;
  105. #endif // if OAU && ! UNICODE
  106. return rCode;
  107. }
  108. /*---------------------------------------------------------------------------
  109. NAME : osItoA
  110. PURPOSE : Gets the string representation of an integer
  111. INPUTS : inVal - the integer in concern
  112. lpsz - the string representation
  113. OUTPUT : the string representation of inVal will be returned via lpsz
  114. NOTES :
  115. ---------------------------------------------------------------------------*/
  116. VOID FAR osItoA (int inVal, LPXSTR lpsz)
  117. {
  118. char szlTmp[20] ;
  119. _itoa(inVal, szlTmp, 10) ;
  120. #ifdef OAU
  121. MultiByteToWideChar(CP_ACP,
  122. MB_PRECOMPOSED,
  123. szlTmp,
  124. -1,
  125. lpsz,
  126. 20);
  127. #else // OAU
  128. osStrCpy(lpsz, szlTmp) ;
  129. #endif // OAU
  130. }
  131. /*---------------------------------------------------------------------------
  132. NAME : osLtoA
  133. PURPOSE : Gets the string representation of a long integer
  134. INPUTS : inVal - the long integer in concern
  135. lpsz - the string representation
  136. OUTPUT : the string representation of inVal will be returned via lpsz
  137. NOTES :
  138. ---------------------------------------------------------------------------*/
  139. VOID FAR osLtoA (long inVal, LPXSTR lpsz)
  140. {
  141. char szlTmp[20] ;
  142. _ltoa(inVal, szlTmp, 10) ;
  143. #ifdef OAU
  144. MultiByteToWideChar(CP_ACP,
  145. MB_PRECOMPOSED,
  146. szlTmp,
  147. -1,
  148. lpsz,
  149. 20);
  150. #else // OAU
  151. osStrCpy(lpsz, szlTmp) ;
  152. #endif // OAU
  153. }
  154. /*---------------------------------------------------------------------------
  155. NAME : osAtoL
  156. PURPOSE : Gets the long integer from a string representing that value
  157. INPUTS : lpsz - the string representation
  158. OUTPUT : the long integer
  159. NOTES :
  160. ---------------------------------------------------------------------------*/
  161. long FAR osAtoL (LPXSTR lpsz)
  162. {
  163. #ifdef OAU
  164. char szlTmp[20];
  165. WideCharToMultiByte(CP_ACP,
  166. 0,
  167. lpsz,
  168. -1,
  169. szlTmp,
  170. 20,
  171. NULL,
  172. NULL);
  173. return atol(szlTmp) ;
  174. #else
  175. return atol(lpsz) ;
  176. #endif
  177. }
  178. /*---------------------------------------------------------------------------
  179. NAME : osGetNetDrive
  180. PURPOSE : Establish/Break a net connection
  181. INPUTS : lpszNetDir - string to receieve the network drive letter
  182. bnAct - flag for establishing or breaking the net connection
  183. TRUE: establish a net connection
  184. FALSE: break a net connection
  185. OUTPUT : True if net connect is established/broken successfully
  186. NOTES : Since Win32s has no API's that support net work action; this
  187. routine does nothing for right now. It can be modified to
  188. establish/break a net connection programmatically in the future.
  189. ---------------------------------------------------------------------------*/
  190. BOOL FAR osGetNetDrive(LPXSTR lpszNetDir, LPXSTR lpUNCDir, BOOL /*bnAct*/) // [4]
  191. {
  192. osStrCpy(lpszNetDir, XSTR("z:\\tmp\\")) ;
  193. osStrCpy(lpUNCDir, XSTR("\\\\apputest\\slm\\tmp\\")) ;
  194. return TRUE ;
  195. }
  196. /*---------------------------------------------------------------------------
  197. NAME : osCreateGuid
  198. PURPOSE : Converts a GUID value from string to GUID format
  199. INPUTS : lpszGuid - string contains the desired GUID value
  200. OUTPUT : pointer to the GUID structure
  201. NOTES : caller is responsible to free up the memory after used
  202. ---------------------------------------------------------------------------*/
  203. GUID FAR * osCreateGuid(LPXSTR lpszGuid)
  204. {
  205. GUID FAR * lpGuid ;
  206. HRESULT hRes ;
  207. lpGuid = (GUID FAR *) osAllocSpaces(sizeof(GUID)*2) ;// allocate space
  208. // for the Guid
  209. if ( lpGuid )
  210. { // convert string to GUID format
  211. hRes = CLSIDFromStringX(lpszGuid, (LPCLSID)lpGuid);
  212. if ( LOWORD (hRes) )
  213. {
  214. osDeAllocSpaces ((LPXSTR)lpGuid) ; // release space before exit
  215. return NULL ;
  216. }
  217. else
  218. return lpGuid ; // return pointer to the
  219. } // GUID structure
  220. else
  221. return NULL ; // no space is allocated
  222. }
  223. /*---------------------------------------------------------------------------
  224. NAME : osRetrieveGuid
  225. PURPOSE : Converts a GUID structure to a readable string format
  226. INPUTS : lpszGuid - string representation of the GUID will be returned
  227. GUID - the GUID structure in concern
  228. OUTPUT : True if conversion is succeed
  229. NOTES :
  230. ---------------------------------------------------------------------------*/
  231. BOOL FAR osRetrieveGuid (LPXSTR lpszGuid, GUID inGuid)
  232. {
  233. LPOLESTR lpszTmp ;
  234. HRESULT hRes ;
  235. // allocate memory for the string
  236. hRes = StringFromCLSID((REFCLSID) inGuid, &lpszTmp) ;
  237. if ( LOWORD (hRes) ) // representation
  238. {
  239. ppmalloc->Free(lpszTmp) ;
  240. return FALSE ;
  241. }
  242. else
  243. {
  244. #ifdef OAU
  245. osStrCpy (lpszGuid, lpszTmp) ;
  246. #else
  247. WideCharToMultiByte(CP_ACP,
  248. 0,
  249. lpszTmp,
  250. -1,
  251. lpszGuid,
  252. 40,
  253. NULL,
  254. NULL);
  255. #endif
  256. ppmalloc->Free(lpszTmp) ;
  257. return TRUE ;
  258. }
  259. }
  260. /*---------------------------------------------------------------------------
  261. NAME : osGetSize
  262. PURPOSE : returns size of the input data
  263. INPUTS : inVT - data type; WORD
  264. OUTPUT : size of inVT; WORD
  265. NOTES :
  266. ---------------------------------------------------------------------------*/
  267. WORD FAR osGetSize (WORD inVT)
  268. {
  269. WORD tSize ;
  270. switch ( inVT )
  271. {
  272. case VT_I2:
  273. tSize = sizeof(short) ;
  274. break ;
  275. case VT_I4:
  276. tSize = sizeof(long) ;
  277. break ;
  278. case VT_R4:
  279. tSize = sizeof(float) ;
  280. break ;
  281. case VT_R8:
  282. tSize = sizeof(double) ;
  283. break ;
  284. case VT_CY:
  285. tSize = sizeof(CY) ;
  286. break ;
  287. case VT_DATE:
  288. tSize = sizeof(DATE) ;
  289. break ;
  290. case VT_BSTR:
  291. tSize = sizeof(BSTR) ;
  292. break ;
  293. case VT_ERROR:
  294. tSize = sizeof(SCODE) ;
  295. break ;
  296. case VT_BOOL:
  297. tSize = sizeof(VARIANT_BOOL) ;
  298. break ;
  299. case VT_VARIANT:
  300. tSize = sizeof(VARIANT) ;
  301. break ;
  302. case VT_I1:
  303. tSize = sizeof(char) ;
  304. break ;
  305. case VT_UI1:
  306. tSize = sizeof(char) ;
  307. break ;
  308. case VT_UI2:
  309. tSize = sizeof(short) ;
  310. break ;
  311. case VT_UI4:
  312. tSize = sizeof(long) ;
  313. break ;
  314. case VT_I8:
  315. tSize = sizeof(long)*2 ;
  316. break ;
  317. case VT_UI8:
  318. tSize = sizeof(long)*2 ;
  319. break ;
  320. case VT_INT:
  321. tSize = sizeof(int) ;
  322. break ;
  323. case VT_UINT:
  324. tSize = sizeof(int) ;
  325. break ;
  326. case VT_VOID:
  327. tSize = 0 ;
  328. break ;
  329. case VT_HRESULT:
  330. tSize = sizeof(HRESULT) ;
  331. break ;
  332. case VT_LPSTR:
  333. tSize = sizeof(LPSTR) ;
  334. break ;
  335. case VT_PTR:
  336. tSize = 4 ;
  337. break ;
  338. case VT_SAFEARRAY:
  339. tSize = sizeof(ARRAYDESC FAR *) ;
  340. break ;
  341. case VT_DISPATCH:
  342. tSize = 4 ;
  343. break ;
  344. case VT_UNKNOWN:
  345. tSize = 4 ;
  346. break ;
  347. default:
  348. tSize = 1 ;
  349. break ;
  350. }
  351. return tSize ;
  352. }
  353. /*---------------------------------------------------------------------------
  354. NAME : osGetAlignment
  355. PURPOSE : returns value of the alignment
  356. INPUTS : inVT - data type; WORD
  357. mAlign - max possible alignment; WORD
  358. OUTPUT : value of the aliangment; WORD
  359. NOTES : value is machine dependent:
  360. Win16 = 1 (everything is packed -> always = 1)
  361. Win32 = natural alignment; max is 4-byte align
  362. mac = everything is on the even-byte boundary
  363. see silver\cl\clutil.cxx for a table of the alignement information
  364. ---------------------------------------------------------------------------*/
  365. WORD FAR osGetAlignment (WORD inVT, WORD mAlign)
  366. {
  367. WORD expAlign ;
  368. expAlign = osGetSize(inVT) ; // check size of the data
  369. return ( expAlign <= mAlign ? expAlign : mAlign ) ;
  370. }
  371. /*---------------------------------------------------------------------------
  372. NAME : osGetEnumType
  373. PURPOSE : return the type of an enum member
  374. INPUTS : none
  375. OUTPUT : VT_I2 for Win16; VARTYPE
  376. NOTES :
  377. ---------------------------------------------------------------------------*/
  378. VARTYPE FAR osGetEnumType ()
  379. {
  380. return VT_I4 ;
  381. }
  382. /*---------------------------------------------------------------------------
  383. NAME : osOleInit
  384. PURPOSE : Calls OleInitialize and returns its return code
  385. INPUTS : none
  386. OUTPUT : return code from calling OleInitialize; HRESULT
  387. NOTES :
  388. ---------------------------------------------------------------------------*/
  389. HRESULT FAR osOleInit ()
  390. {
  391. HRESULT hRes ;
  392. hRes = OleInitialize(NULL) ; // Ole initialization
  393. #ifdef DEBUG
  394. if ( hRes != NOERROR )
  395. return hRes ;
  396. hRes = GetMallocSpy(&g_IMallocSpy) ; // [5]
  397. hRes = CoRegisterMallocSpy(g_IMallocSpy) ;
  398. if ( hRes != NOERROR )
  399. OleUninitialize ;
  400. else
  401. hRes = CoGetMalloc(MEMCTX_TASK, &ppmalloc) ;
  402. #else
  403. if ( !LOWORD(hRes) ) // allocate memory for use in the
  404. hRes = CoGetMalloc(MEMCTX_TASK, &ppmalloc) ; // the program
  405. #endif
  406. return hRes ;
  407. }
  408. /*---------------------------------------------------------------------------
  409. NAME : osOleUninit
  410. PURPOSE : Calls OleUnInitialize
  411. INPUTS : none
  412. OUTPUT : none
  413. NOTES :
  414. ---------------------------------------------------------------------------*/
  415. VOID FAR osOleUninit ()
  416. {
  417. ppmalloc->Release () ; // release memory that was been
  418. OleUninitialize (); // allocated at OleInitialize
  419. #ifdef DEBUG
  420. CoRevokeMallocSpy () ; // [5]
  421. #endif
  422. }
  423. /*---------------------------------------------------------------------------
  424. NAME : osMessage
  425. PURPOSE : Displays a MessageBox
  426. INPUTS : Message to be displayed; a string of characters
  427. OUTPUT : none
  428. NOTES :
  429. ---------------------------------------------------------------------------*/
  430. VOID FAR osMessage (LPXSTR lpszMsg, LPXSTR lpszTitle)
  431. {
  432. #if defined (OAU) && !defined (UNICODE)// [1]
  433. char szBufferM[256];
  434. char szBufferT[256];
  435. WideCharToMultiByte(CP_ACP,
  436. 0,
  437. lpszMsg,
  438. -1,
  439. szBufferM,
  440. 256,
  441. NULL,
  442. NULL);
  443. WideCharToMultiByte(CP_ACP,
  444. 0,
  445. lpszTitle,
  446. -1,
  447. szBufferT,
  448. 256,
  449. NULL,
  450. NULL);
  451. MessageBox (NULL, szBufferM, szBufferT, MB_OK) ;
  452. #else // if OAU && ! UNICODE
  453. MessageBox (NULL, lpszMsg, lpszTitle, MB_OK) ;
  454. #endif // if OAU && ! UNICODE
  455. }
  456. /*---------------------------------------------------------------------------
  457. NAME : osSetErrorMode
  458. PURPOSE : For Win16 compatibility
  459. INPUTS : eFlag - UINT
  460. OUTPUT : UINT
  461. NOTES : This routine is for Win16 compatibility purposes
  462. ---------------------------------------------------------------------------*/
  463. UINT FAR osSetErrorMode (UINT eFlag)
  464. {
  465. return eFlag ;
  466. }
  467. /*---------------------------------------------------------------------------
  468. NAME : WinMain
  469. PURPOSE : Entry point of the test
  470. INPUTS : standard inputs
  471. OUTPUT : None
  472. NOTES :
  473. ---------------------------------------------------------------------------*/
  474. int FAR pascal WinMain(HINSTANCE /*hInstanceCur*/, HINSTANCE /*hInstancePrev*/, LPSTR lpCmdLineA, int /*nCmdShow*/)
  475. {
  476. #ifdef OAU
  477. XCHAR lpCmdLine[128];
  478. MultiByteToWideChar(CP_ACP,
  479. MB_PRECOMPOSED,
  480. lpCmdLineA,
  481. -1,
  482. lpCmdLine,
  483. 128);
  484. #else //OAU
  485. #define lpCmdLine lpCmdLineA
  486. #endif //OAU
  487. mainEntry (lpCmdLine) ; // entry point for all programs
  488. return 1 ;
  489. }
  490. //======================= Wrapper functions ==================================
  491. #if !defined(OAU)
  492. /*---------------------------------------------------------------------------
  493. NAME : CreateTypeLibA
  494. PURPOSE : Creates a typelib name of which is an ANSI string
  495. INPUTS : syskind - os that the type library is created on; SYSKIND
  496. szFile - name of type library; ANSI string
  497. ppctlib - pointer to the created library
  498. OUTPUT : None
  499. NOTES :
  500. ---------------------------------------------------------------------------*/
  501. STDAPI
  502. CreateTypeLibA(SYSKIND syskind, char * szFile, ICreateTypeLibA * * ppctlib)
  503. { // [1]
  504. OLECHAR szFileW[_MAX_PATH] ;
  505. ICreateTypeLib * ptlibW ;
  506. HRESULT hresult ;
  507. MultiByteToWideChar(CP_ACP,
  508. MB_PRECOMPOSED,
  509. szFile,
  510. -1,
  511. szFileW,
  512. _MAX_PATH);
  513. hresult = CreateTypeLib(syskind, szFileW, &ptlibW);
  514. if (hresult == NOERROR)
  515. {
  516. hresult = ptlibW->QueryInterface(IID_ICreateTypeLibA, (VOID **)ppctlib);
  517. ptlibW->Release();
  518. }
  519. return hresult;
  520. }
  521. /*---------------------------------------------------------------------------
  522. NAME : LHashValOfNameSysA
  523. PURPOSE : Finds the hash value for a given string
  524. INPUTS : syskind - current operating system
  525. lcid - lcid of the currenet system
  526. szName - string in concern; ANSI string
  527. OUTPUT : Return LHashValOfNameSys
  528. NOTES :
  529. ---------------------------------------------------------------------------*/
  530. STDAPI_(unsigned long)
  531. LHashValOfNameSysA(SYSKIND syskind, LCID lcid, char * szName)
  532. {
  533. OLECHAR szNameW[_MAX_PATH];
  534. if ( szName )
  535. {
  536. MultiByteToWideChar(CP_ACP,
  537. MB_PRECOMPOSED,
  538. szName,
  539. -1,
  540. szNameW,
  541. _MAX_PATH);
  542. return LHashValOfNameSys(syskind, lcid, szNameW) ;
  543. }
  544. else
  545. return LHashValOfNameSys(syskind, lcid, NULL) ;
  546. }
  547. /*---------------------------------------------------------------------------
  548. NAME : LoadTypeLibA
  549. PURPOSE : Loads a typelib name of which is an ANSI string
  550. INPUTS : szFile - name of type library; ANSI string
  551. pptlib - pointer to the loaded library
  552. OUTPUT : None
  553. NOTES :
  554. ---------------------------------------------------------------------------*/
  555. STDAPI
  556. LoadTypeLibA(char * szFile, ITypeLibA * * pptlib)
  557. {
  558. OLECHAR szFileW[_MAX_PATH];
  559. ITypeLib * ptlibW;
  560. HRESULT hresult = (HRESULT) E_INVALIDARG ;
  561. if ( szFile && pptlib )
  562. {
  563. MultiByteToWideChar(CP_ACP,
  564. MB_PRECOMPOSED,
  565. szFile,
  566. -1,
  567. szFileW,
  568. _MAX_PATH);
  569. hresult = LoadTypeLibEx(szFileW, REGKIND_NONE, &ptlibW);
  570. if (hresult == NOERROR) // convert the wide pointer to a narrow
  571. { // one
  572. hresult = ptlibW->QueryInterface(IID_ITypeLibA, (VOID **)pptlib);
  573. ptlibW->Release();
  574. }
  575. }
  576. return hresult;
  577. }
  578. /*---------------------------------------------------------------------------
  579. NAME : LoadRegTypeLibA
  580. PURPOSE : Loads a typelib according to the info from the registry
  581. INPUTS : rguid - GUID of the library
  582. wVerMajor - Major version number of the library
  583. wVerMinor - Minor version number of the library
  584. pptlib - pointer to receive the library; an ANSI pointer
  585. OUTPUT : result from LoadRegTypeLib
  586. NOTES :
  587. ---------------------------------------------------------------------------*/
  588. STDAPI
  589. LoadRegTypeLibA(REFGUID rguid, unsigned short wVerMajor, unsigned short wVerMinor, LCID lcid, ITypeLibA * * pptlib)
  590. {
  591. ITypeLib * ptlibW;
  592. HRESULT hresult;
  593. hresult = LoadRegTypeLib(rguid, wVerMajor, wVerMinor, lcid, &ptlibW);
  594. if (hresult == NOERROR) { // convert the wide pointer to a narrow
  595. hresult = ptlibW->QueryInterface(IID_ITypeLibA, (VOID **)pptlib);
  596. ptlibW->Release(); // one
  597. }
  598. return hresult;
  599. }
  600. /*---------------------------------------------------------------------------
  601. NAME : RegisterTypeLibA
  602. PURPOSE : Adds information of a library to the system registry
  603. INPUTS : ptlib - pointer to the library; an ANSI pointer
  604. szFullPath - pathspec of the library; ANSI string
  605. szHelpDir - pathspec of the help file; ANSI string
  606. OUTPUT : result from RegisterTypeLib
  607. NOTES :
  608. ---------------------------------------------------------------------------*/
  609. STDAPI
  610. RegisterTypeLibA(ITypeLibA FAR * ptlib, char * szFullPath, char * szHelpDir)
  611. {
  612. OLECHAR szPathW[_MAX_PATH];
  613. OLECHAR szHelpW[_MAX_PATH];
  614. ITypeLib FAR * ptlibW = NULL ;
  615. BOOL PathOk = FALSE , HelpOk = FALSE ;
  616. HRESULT hresult = (HRESULT) TYPE_E_LIBNOTREGISTERED ;
  617. if ( !ptlib ) // ptlib == NULL
  618. return (HRESULT) E_INVALIDARG ;
  619. ptlibW = ITypeLibWFromA(ptlib) ; // convert the narrow pointer to a wide
  620. // one
  621. if ( ptlibW ) // check if the pathspec is NULL or not
  622. { // if it is not, convert the ANSI path
  623. if ( szFullPath ) // to an UNICODE path
  624. {
  625. MultiByteToWideChar(CP_ACP,
  626. MB_PRECOMPOSED,
  627. szFullPath,
  628. -1,
  629. szPathW,
  630. _MAX_PATH);
  631. PathOk = TRUE ;
  632. }
  633. if ( szHelpDir )
  634. {
  635. MultiByteToWideChar(CP_ACP,
  636. MB_PRECOMPOSED,
  637. szHelpDir,
  638. -1,
  639. szHelpW,
  640. _MAX_PATH);
  641. HelpOk = TRUE ;
  642. }
  643. if ( PathOk && HelpOk ) // if both pathspec's are not NULL
  644. hresult = RegisterTypeLib(ptlibW, szPathW, szHelpW);
  645. else
  646. {
  647. if ( PathOk ) // here if helpdir is NULL
  648. hresult = RegisterTypeLib(ptlibW, szPathW, NULL);
  649. else // here if pathspec of library is NULL
  650. hresult = RegisterTypeLib(ptlibW, NULL, szHelpW);
  651. }
  652. ptlibW->Release();
  653. }
  654. return hresult;
  655. }
  656. /*---------------------------------------------------------------------------
  657. NAME : CLSIDFromStringA
  658. PURPOSE : Converts an ANSI string to a UUID
  659. INPUTS : szG - string that represents a UUID; ANSI string
  660. lpG - pointer to the UUID
  661. OUTPUT : return code form CLSIDFromString
  662. NOTES :
  663. ---------------------------------------------------------------------------*/
  664. STDAPI
  665. CLSIDFromStringA(char * szG, LPCLSID lpG)
  666. {
  667. OLECHAR szGW[100];
  668. MultiByteToWideChar(CP_ACP,
  669. MB_PRECOMPOSED,
  670. szG,
  671. -1,
  672. szGW,
  673. 100);
  674. return CLSIDFromString(szGW, (LPCLSID)lpG) ;
  675. }
  676. /*---------------------------------------------------------------------------
  677. NAME : IIDFromStringA
  678. PURPOSE : Converts an ANSI string to an IID
  679. INPUTS : szA - string that represents a IID; ANSI string
  680. lpiid - pointer to the iid
  681. OUTPUT : Return code form IIDFromString
  682. NOTES :
  683. ---------------------------------------------------------------------------*/
  684. STDAPI
  685. IIDFromStringA(LPSTR lpszA, LPIID lpiid)
  686. {
  687. OLECHAR szAW[100];
  688. MultiByteToWideChar(CP_ACP,
  689. MB_PRECOMPOSED,
  690. lpszA,
  691. -1,
  692. szAW,
  693. 100);
  694. return IIDFromString(szAW, (LPIID)lpiid) ;
  695. }
  696. /*---------------------------------------------------------------------------
  697. NAME : StgCreateDocfileA
  698. PURPOSE : Creates a doc file
  699. INPUTS : pwcsName - name of the doc file; ANSI string
  700. grfMode - creation mode
  701. ppstgOpenA - pointer the storage
  702. OUTPUT : Return code from StgCreateDocfile
  703. NOTES :
  704. ---------------------------------------------------------------------------*/
  705. STDAPI StgCreateDocfileA(LPCSTR pwcsName, DWORD grfMode, DWORD reserved, IStorage * *ppstgOpenA)
  706. {
  707. OLECHAR szNameW[100];
  708. MultiByteToWideChar(CP_ACP,
  709. MB_PRECOMPOSED,
  710. pwcsName,
  711. -1,
  712. szNameW,
  713. 100);
  714. return StgCreateDocfile(szNameW, grfMode, reserved, ppstgOpenA) ;
  715. }
  716. /*---------------------------------------------------------------------------
  717. NAME : CreateFileMonikerA
  718. PURPOSE : Creates a doc file
  719. INPUTS : szfName - name of the file spec; ANSI string
  720. pmk - pointer the moniker
  721. OUTPUT : Return code from CreateFileMoniker
  722. NOTES :
  723. ---------------------------------------------------------------------------*/
  724. STDAPI CreateFileMonikerA (char * szfName, LPMONIKER FAR * pmk) // [2]
  725. {
  726. OLECHAR szNameW[128];
  727. MultiByteToWideChar(CP_ACP,
  728. MB_PRECOMPOSED,
  729. szfName,
  730. -1,
  731. szNameW,
  732. 128);
  733. return CreateFileMoniker(szNameW, pmk) ;
  734. }
  735. #endif // if !OAU
  736. #if defined(OAU) && !defined(UNICODE) // [1]
  737. /*---------------------------------------------------------------------------
  738. NAME : osKillFile
  739. PURPOSE : Removes a specific file from the disk
  740. INPUTS : szFile - name of file to be removed; UNICODE string
  741. OUTPUT : Output from DeleteFile
  742. NOTES :
  743. ---------------------------------------------------------------------------*/
  744. int osKillFile (XCHAR * szFile)
  745. {
  746. char szBuffer[256];
  747. WideCharToMultiByte(CP_ACP,
  748. 0,
  749. szFile,
  750. -1,
  751. szBuffer,
  752. 256,
  753. NULL,
  754. NULL);
  755. return DeleteFile (szBuffer) ;
  756. }
  757. /*---------------------------------------------------------------------------
  758. NAME : osRmDir
  759. PURPOSE : Removes a specific directory from the disk
  760. INPUTS : szDir - name of directory to be removed; UNICODE string
  761. OUTPUT : Output from RemoveDirectory
  762. NOTES :
  763. ---------------------------------------------------------------------------*/
  764. int osRmDir (XCHAR * szDir)
  765. {
  766. char szBuffer[256];
  767. WideCharToMultiByte(CP_ACP,
  768. 0,
  769. szDir,
  770. -1,
  771. szBuffer,
  772. 256,
  773. NULL,
  774. NULL);
  775. return RemoveDirectory(szBuffer) ;
  776. }
  777. /*---------------------------------------------------------------------------
  778. NAME : LCMapStringX
  779. PURPOSE : Converts one string of characters to another
  780. INPUTS : lcid - Locale context fo the mapping; LCID
  781. dw1 - type of mapping; unsigned long
  782. sz1 - string for conversion; UNICODE string
  783. i1 - number of characters in sz1; int
  784. sz2 - buffer to store the resulting string; UNICODE string
  785. i2 - number of characters converted
  786. OUTPUT : Output from LCMapStringA
  787. NOTES :
  788. ---------------------------------------------------------------------------*/
  789. int LCMapStringX (LCID lcid, DWORD dw1, LPXSTR sz1, int i1, LPXSTR sz2, int i2) // [3]
  790. {
  791. char szBuf1[300];
  792. char szBuf2[300];
  793. int retval ;
  794. WideCharToMultiByte(CP_ACP,
  795. 0,
  796. sz1,
  797. -1,
  798. szBuf1,
  799. 300,
  800. NULL,
  801. NULL);
  802. retval = LCMapStringA(lcid, dw1, szBuf1, i1, szBuf2, i2) ;
  803. MultiByteToWideChar(CP_ACP,
  804. MB_PRECOMPOSED,
  805. szBuf2,
  806. -1,
  807. sz2,
  808. 300);
  809. return retval ;
  810. }
  811. #endif // if OAU && !UNICODE
  812. #ifdef OAU
  813. /*---------------------------------------------------------------------------
  814. NAME : fopenX
  815. PURPOSE : Opens a file for read/write
  816. INPUTS : szFilName - name of file to be open; UNICODE string
  817. szMode - purpose for the file; UNICODE string
  818. OUTPUT : Return code from fopen
  819. NOTES :
  820. ---------------------------------------------------------------------------*/
  821. FILE * fopenX(XCHAR * szFilName, XCHAR * szMode)
  822. {
  823. char szANSITmp1[256];
  824. char szANSITmp2[256];
  825. WideCharToMultiByte(CP_ACP,
  826. 0,
  827. szFilName,
  828. -1,
  829. szANSITmp1,
  830. 256,
  831. NULL,
  832. NULL);
  833. WideCharToMultiByte(CP_ACP,
  834. 0,
  835. szMode,
  836. -1,
  837. szANSITmp2,
  838. 256,
  839. NULL,
  840. NULL);
  841. return fopen(szANSITmp1, szANSITmp2) ; // open output as an ANSI file
  842. }
  843. /*---------------------------------------------------------------------------
  844. NAME : fputsX
  845. PURPOSE : Writes to a file for read/write
  846. INPUTS : szBuf - data to be written; UNICODE string
  847. hFile - handle of the output file
  848. OUTPUT : Return code from fputs
  849. NOTES :
  850. ---------------------------------------------------------------------------*/
  851. int fputsX(XCHAR *szBuf, FILE *hFile)
  852. {
  853. char szANSITmp[512];
  854. WideCharToMultiByte(CP_ACP,
  855. 0,
  856. szBuf,
  857. -1,
  858. szANSITmp,
  859. 512,
  860. NULL,
  861. NULL);
  862. return fputs(szANSITmp, hFile) ;
  863. }
  864. #endif