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.

106 lines
2.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  4. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  5. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  6. // PARTICULAR PURPOSE.
  7. //
  8. // Copyright (c) Microsoft Corporation, 1999 - 1999. All Rights Reserved.
  9. //
  10. // PROGRAM: loccat.cxx
  11. //
  12. // PURPOSE: Illustrates LocateCatalogs usage
  13. //
  14. // PLATFORM: Windows
  15. //
  16. //--------------------------------------------------------------------------
  17. #define UNICODE
  18. #include <stdio.h>
  19. #include <wchar.h>
  20. #include <windows.h>
  21. #include <ole2.h>
  22. #include <ntquery.h>
  23. void Usage()
  24. {
  25. printf( "usage: loccat path\n" );
  26. exit( 1 );
  27. } //Usage
  28. //+-------------------------------------------------------------------------
  29. //
  30. // Function: LookupCatalogs
  31. //
  32. // Synopsis: Looks for catalogs and machines matching the scope
  33. //
  34. // Arguments: [pwcScope] - The scope used to find the catalog(s)
  35. //
  36. // Returns: Result of the operation
  37. //
  38. //--------------------------------------------------------------------------
  39. HRESULT LookupCatalog( WCHAR const * pwcScope )
  40. {
  41. HRESULT hr;
  42. int iBmk = 0;
  43. do
  44. {
  45. WCHAR awcMachine[ MAX_PATH ], awcCatalog[ MAX_PATH ];
  46. ULONG cwcMachine = sizeof awcMachine / sizeof WCHAR;
  47. ULONG cwcCatalog = sizeof awcCatalog / sizeof WCHAR;
  48. hr = LocateCatalogs( pwcScope, // scope to lookup
  49. iBmk, // go with the first match
  50. awcMachine, // returns the machine
  51. &cwcMachine, // buffer size in/out
  52. awcCatalog, // returns the catalog
  53. &cwcCatalog ); // buffer size in/out
  54. if ( S_OK == hr )
  55. {
  56. printf( "machine: '%ws', catalog: '%ws'\n", awcMachine, awcCatalog );
  57. iBmk++;
  58. }
  59. else if ( S_FALSE == hr )
  60. {
  61. // no more catalogs...
  62. if ( 0 == iBmk )
  63. printf( "no catalogs matched the path %ws\n", pwcScope );
  64. }
  65. else if ( FAILED( hr ) )
  66. {
  67. printf( "LocateCatalogs failed: %#x\n", hr );
  68. }
  69. } while ( S_OK == hr );
  70. return hr;
  71. } //LookupCatalogs
  72. //+-------------------------------------------------------------------------
  73. //
  74. // Function: wmain
  75. //
  76. // Synopsis: Entry point for the app.
  77. //
  78. // Arguments: [argc] - Argument count
  79. // [argv] - Arguments
  80. //
  81. //--------------------------------------------------------------------------
  82. extern "C" int __cdecl wmain( int argc, WCHAR * argv[] )
  83. {
  84. if ( 2 != argc )
  85. Usage();
  86. HRESULT hr = LookupCatalog( argv[1] );
  87. if ( FAILED( hr ) )
  88. return -1;
  89. return 0;
  90. } //wmain