Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include <fcntl.h>
  4. #include <io.h>
  5. #include <stdio.h>
  6. #define MAX 256
  7.  
  8. using namespace std;
  9. //Permitir que o mesmo código possa funcionar para ASCII ou UNICODE
  10. #ifdef UNICODE
  11. #define tcout wcout
  12. #define tcin wcin
  13. #define tstring wstring
  14. #else
  15. #define tcout cout
  16. #define tcin cin
  17. #define tstring string
  18. #endif
  19.  
  20. int _tmain(int argc, LPTSTR argv[]) {
  21. TCHAR fileN[MAX], str[MAX], numS[MAX], rec[MAX];
  22. int numI = -1;
  23. PROCESS_INFORMATION infoProcesso;
  24. STARTUPINFO infoSup;
  25. ZeroMemory(&infoSup, sizeof(infoSup));
  26.  
  27. //UNICODE: Por defeito, a consola Windows não processe caracteres wide.
  28. //A maneira mais fácil para ter esta funcionalidade é chamar _setmode:
  29. #ifdef UNICODE
  30. _setmode(_fileno(stdin), _O_WTEXT);
  31. _setmode(_fileno(stdout), _O_WTEXT);
  32. #endif
  33.  
  34. //5.a)
  35. /*GetModuleFileName(NULL, fileN, MAX);
  36. _tprintf(TEXT("%s\n\n"), fileN);
  37. fflush(stdin);*/
  38.  
  39. //5.b/c)
  40. /*_tprintf(TEXT("Programa: "));
  41. _fgetts(str, MAX, stdin);
  42. str[_tcslen(str) - 1] = '\0';
  43. CreateProcess(NULL, str, NULL, NULL, 0, 0, NULL, NULL, &infoSup, &infoProcesso);
  44. _tprintf(TEXT("\n"));*/
  45.  
  46. //5.d)
  47. if (argc >= 2) {
  48. numI = _tstoi(argv[1]) - 1;
  49. _stprintf_s(numS, MAX - 1, TEXT(" %d"), numI);
  50. GetModuleFileName(NULL, fileN, MAX);
  51. _tcscpy_s(rec, MAX, fileN);
  52. _tcscat_s(rec, MAX, numS);
  53. _tprintf(TEXT("\n--Número: %d\n"), numI);
  54. }
  55. if (numI > 0) {
  56. CreateProcess(NULL, rec, NULL, NULL, 0, 0, NULL, NULL, &infoSup, &infoProcesso);
  57. }
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement