home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples1.exe / MetaInfo / metainfo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  5.0 KB  |  161 lines

  1. //*****************************************************************************
  2. // File: metainfo.cpp
  3. //
  4. // Copyright (c) 1997-2000 Microsoft Corporation.  All Rights Reserved.
  5. // Microsoft Confidential.
  6. //*****************************************************************************
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include <crtdbg.h>
  10. #include "mdinfo.h"
  11.  
  12. #include "__file__.h"
  13. #include "corver.h"
  14.  
  15. // Global variables
  16. bool g_bSchema = false; 
  17. bool g_bRaw = false;
  18. bool g_bHeader = false;
  19.  
  20. IMetaDataImport *g_pImport = NULL;
  21. IMetaDataDispenserEx *g_pDisp = NULL;
  22.  
  23. void DisplayFile(char* szFile, BOOL isFile, ULONG DumpFilter, char* szObjFile, strPassBackFn pDisplayString);
  24. void DisplayArchive(char* szFile, ULONG DumpFilter, char* szObjName, strPassBackFn pDisplayString);
  25.  
  26. void PrintLogo()
  27. {
  28.     printf("Microsoft (R) NGWS Runtime Meta Data Dump Utility   Version %s\n", VER_FILEVERSION_STR);
  29.     printf(VER_LEGALCOPYRIGHT_DOS_STR);
  30.     printf("\n");
  31. }// PrintLogo
  32.  
  33. void Usage()
  34. {
  35.     printf("\n");
  36.     printf("metainfo [-? | -header | -schema | -raw] [-nologo] [-obj <obj file name>] [<filname> | <file pattern>]\n");
  37.     printf("    -?       Displays this text.\n");
  38.     printf("    -hex     Prints more things in hex as well as words.\n");
  39.     printf("    -header  Prints MetaData header information and sizes.\n");
  40.     printf("    -csv     Prints the header sizes in Comma Separated format.\n");
  41.     printf("    -unsat   Prints unresolved externals.\n");
  42.     printf("    -schema  Prints the MetaData schema information.\n");
  43.     printf("    -raw     Prints the raw MetaData tables.\n");
  44.     printf("    -heaps   Prints the raw heaps (only if -raw).\n");
  45.     printf("    -nologo  Do not display the logo and MVID.\n");
  46.     printf("    -obj <objFileName>\n");
  47.     printf("             Prints the MetaData for the specified obj file in the given \n");
  48.     printf("             archive(.lib) - e.g metainfo libc.lib -obj wMSILWinCRTStartup.obj\n");
  49.  
  50.     MDInfo::Error("");
  51. }
  52.  
  53. void DisplayString(char *str)
  54. {
  55.     printf("%s", str);
  56. }
  57.  
  58. int _cdecl main(int argc, char** argv)
  59. {
  60.     char *pArg = NULL;
  61.     char *szObjName = NULL;
  62.     ULONG DumpFilter = MDInfo::dumpDefault;
  63.     HRESULT hr = 0;
  64.     BOOL    fWantHelp=FALSE;
  65.     
  66.     // Validate incoming arguments
  67.     for (int i=1;  i<argc;  i++)
  68.     {
  69.         const char *szArg = argv[i];
  70.         if (*szArg == '-' || *szArg == '/')
  71.         {
  72.             if (lstrcmpi(szArg + 1, "?") == 0)
  73.                 fWantHelp=TRUE;
  74.  
  75.             else if (lstrcmpi(szArg + 1, "nologo") == 0)
  76.                 DumpFilter |= MDInfo::dumpNoLogo;
  77.  
  78.             else if (lstrcmpi(szArg + 1, "Hex") == 0)
  79.                 DumpFilter |= MDInfo::dumpMoreHex;
  80.  
  81.             else if (lstrcmpi(szArg + 1, "header") == 0)
  82.                 DumpFilter |= MDInfo::dumpHeader;
  83.  
  84.             else if (lstrcmpi(szArg + 1, "csv") == 0)
  85.                 DumpFilter |= MDInfo::dumpCSV;
  86.  
  87.             else if (lstrcmpi(szArg + 1, "raw") == 0)
  88.                 DumpFilter |= MDInfo::dumpRaw;
  89.  
  90.             else if (lstrcmpi(szArg + 1, "heaps") == 0)
  91.                 DumpFilter |= MDInfo::dumpRawHeaps;
  92.  
  93.             else if (lstrcmpi(szArg + 1, "schema") == 0)
  94.                 DumpFilter |= MDInfo::dumpSchema;
  95.  
  96.             else if (lstrcmpi(szArg + 1, "unsat") == 0)
  97.                 DumpFilter |= MDInfo::dumpUnsat;
  98.  
  99.             else if (lstrcmpi(szArg + 1, "stats") == 0)
  100.                 DumpFilter |= MDInfo::dumpStats;
  101.  
  102.             else if (lstrcmpi(szArg + 1, "obj") == 0)
  103.             {
  104.                 if (++i == argc)
  105.                     Usage();
  106.                 else
  107.                     szObjName = argv[i];
  108.             }
  109.         }
  110.         else
  111.             pArg = argv[i];
  112.     }
  113.  
  114.     // Print banner.
  115.     if (!(DumpFilter & MDInfo::dumpNoLogo))
  116.         PrintLogo();
  117.  
  118.  
  119.     if (!pArg || fWantHelp)
  120.         Usage();
  121.  
  122.     
  123.     // Init and run.
  124.     CoInitialize(0);    
  125.  
  126.     hr = CoCreateInstance(CLSID_CorMetaDataDispenser, NULL, CLSCTX_INPROC_SERVER, 
  127.                   IID_IMetaDataDispenserEx, (void **) &g_pDisp);
  128.     if(FAILED(hr)) MDInfo::Error("Unable to CoCreate Meta-data Dispenser", hr);
  129.  
  130.     // Loop through all files in the file pattern passed
  131.     WIN32_FIND_DATA fdFiles;
  132.     HANDLE hFind;
  133.     char szSpec[_MAX_PATH];
  134.     char szDrive[_MAX_DRIVE];
  135.     char szDir[_MAX_DIR];
  136.  
  137.     hFind = FindFirstFile(pArg, &fdFiles);
  138.  
  139.     if (hFind == INVALID_HANDLE_VALUE)
  140.     {
  141.         DisplayFile(pArg, false, DumpFilter, szObjName, DisplayString);
  142.     }
  143.     else
  144.     {
  145.         // Convert relative paths to full paths.
  146.         _fullpath(szSpec, pArg, sizeof(szSpec));
  147.         _splitpath(szSpec, szDrive, szDir, NULL, NULL);
  148.         do
  149.         {
  150.             _makepath(szSpec, szDrive, szDir, fdFiles.cFileName, NULL);
  151.             // display the meta data of the file
  152.             DisplayFile(szSpec, true, DumpFilter, szObjName, DisplayString);
  153.         } while (FindNextFile(hFind, &fdFiles)) ;
  154.         FindClose(hFind);
  155.     }
  156.     g_pDisp->Release();
  157.     CoUninitialize();
  158.     return 0;
  159. }
  160.  
  161.