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.

82 lines
2.3 KiB

  1. //---------------------------------------------------------------------------
  2. // ImageCon.cpp - converts from one file format to another
  3. //---------------------------------------------------------------------------
  4. #include "stdafx.h"
  5. #include <uxthemep.h>
  6. #include <utils.h>
  7. #include "SimpStr.h"
  8. #include "Scanner.h"
  9. #include "shlwapip.h"
  10. #include "themeldr.h"
  11. //---------------------------------------------------------------------------
  12. void PrintUsage()
  13. {
  14. wprintf(L"\nUsage: imagecon <input name> <output name> \n");
  15. wprintf(L"\n");
  16. }
  17. //---------------------------------------------------------------------------
  18. extern "C" WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE previnst,
  19. LPTSTR pszCmdLine, int nShowCmd)
  20. {
  21. //---- initialize globals from themeldr.lib ----
  22. ThemeLibStartUp(FALSE);
  23. WCHAR szOutput[_MAX_PATH+1] = {0};
  24. WCHAR szInput[_MAX_PATH+1] = {0};
  25. BOOL fQuietRun = FALSE;
  26. if (! fQuietRun)
  27. {
  28. wprintf(L"Microsoft (R) Image Converter (Version .1)\n");
  29. wprintf(L"Copyright (C) Microsoft Corp 2000. All rights reserved.\n");
  30. }
  31. CScanner scan(pszCmdLine);
  32. BOOL gotem = scan.GetFileName(szInput, ARRAYSIZE(szInput));
  33. if (gotem)
  34. gotem = scan.GetFileName(szOutput, ARRAYSIZE(szOutput));
  35. if (! gotem)
  36. {
  37. PrintUsage();
  38. return 1;
  39. }
  40. HRESULT hr = S_OK;
  41. if (! FileExists(szInput))
  42. hr = MakeError32(STG_E_FILENOTFOUND);
  43. else
  44. {
  45. //---- protect ourselves from crashes ----
  46. try
  47. {
  48. hr = SHConvertGraphicsFile(szInput, szOutput, SHCGF_REPLACEFILE);
  49. }
  50. catch (...)
  51. {
  52. hr = MakeError32(E_FAIL);
  53. }
  54. }
  55. if ((SUCCEEDED(hr)) && (! FileExists(szOutput)))
  56. hr = MakeError32(E_FAIL);
  57. if (FAILED(hr))
  58. {
  59. LPWSTR pszMsgBuff;
  60. FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
  61. | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, hr,
  62. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&pszMsgBuff, 0, NULL);
  63. printf("Error in converting: %S", pszMsgBuff);
  64. return 1;
  65. }
  66. printf("Converted image file to: %S\n", szOutput);
  67. return 0;
  68. }
  69. //---------------------------------------------------------------------------