Guest User

winapi sucks

a guest
Oct 17th, 2026
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. #ifdef _WIN32
  2.     #define psa_execve(psa, childPidVarName, nPidVarName, statusVarName) \
  3.         PROCESS_INFORMATION pProcInfo; \
  4.         ZeroMemory(&pProcInfo, sizeof(pProcInfo)); \
  5.         unsigned int psa##_i, psa##_j; \
  6.         for (psa##_i = 0; psa##_i < 1024; psa##_i++) { \
  7.             if (!psa[psa##_i]) { \
  8.                 psa##_i++; \
  9.                 break; \
  10.             } \
  11.         } \
  12.         char psa##_buffer[2048]; \
  13.         strcat(psa[0], ".exe"); \
  14.         psa_get_cmdline(psa, psa##_i, psa##_j, psa##_buffer); \
  15.         STARTUPINFO si; \
  16.         ZeroMemory(&si, sizeof(si)); /* how is this any different from memset 0? */ \
  17.         printf("buffer = '%s'\n", psa##_buffer); \
  18.         CreateProcess( \
  19.             psa[0], /* application name */ \
  20.             psa##_buffer, /* command line */ \
  21.             NULL, /* process attributes */ \
  22.             NULL, /* thread attributes */ \
  23.             FALSE, /* inherit handles */ \
  24.             0, /* creation flags, whatever that means */ \
  25.             NULL, /* the environment; NULL means copy the parent process's environment */ \
  26.             NULL, /* lpCurrentDirectory; NULL means copy */ \
  27.             &si, /* startupinfo, whatever it is */ \
  28.             &pProcInfo /* process information, which is the actual fucking result of this fucktion */ \
  29.         ); \
  30.         WaitForSingleObject(pProcInfo.hProcess, INFINITE); \
  31.         DWORD dwExitCode; \
  32.         GetExitCodeProcess(pProcInfo.hProcess, &dwExitCode); \
  33.         int statusVarName = (int)dwExitCode; \
  34.         \
  35.         CloseHandle(pProcInfo.hProcess); \
  36.         CloseHandle(pProcInfo.hThread)
  37. #else
  38.     #define psa_execve(psa, childPidVarName, nPidVarName, statusVarName) \
  39.         pid_t childPidVarName = fork(); \
  40.         pid_t nPidVarName = 0; \
  41.         int statusVarName = 0; \
  42.         if (!childPidVarName) { \
  43.             execv(psa[0], psa); \
  44.         } \
  45.         while ((nPidVarName = waitpid(childPidVarName, &statusVarName, 0)) > 0)
  46. #endif
Add Comment
Please, Sign In to add comment