Guest User

Untitled

a guest
Jul 4th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. // bottuum.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4.  
  5. #include <io.h>
  6. #include <windows.h>
  7. #include "stdafx.h"
  8. #include <iostream>
  9.  
  10. int main(int argc, TCHAR* argv[])
  11. {
  12.     if (argc != 3)
  13.     {
  14.         fprintf(stderr, "Usage: %s executable dll\n", argv[0]);
  15.         return 1;
  16.     }
  17.     TCHAR* exe = argv[1];
  18.     TCHAR* dll = argv[2];
  19.    
  20.     fprintf(stdout, "Running: %s // %s", exe, dll);
  21.  
  22.     STARTUPINFO sInfo;
  23.     PROCESS_INFORMATION pInfo;
  24.     ZeroMemory(&sInfo, sizeof(sInfo));
  25.     ZeroMemory(&pInfo, sizeof(pInfo));
  26.     sInfo.cb = sizeof(sInfo);
  27.  
  28.  
  29.     if(!CreateProcess(exe, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &sInfo, &pInfo)) {
  30.         TCHAR szBuf[180];
  31.         LPVOID lpMsgBuf;
  32.         DWORD dw = GetLastError();
  33.         FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |    FORMAT_MESSAGE_FROM_SYSTEM, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL );
  34.         wsprintf(szBuf, L"failed with error %d: %s", dw, lpMsgBuf);
  35.         MessageBox(NULL, szBuf, L"Error", MB_OK);
  36.     }
  37.  
  38.     WaitForSingleObject( pInfo.hProcess, INFINITE );
  39.  
  40.     CloseHandle( pInfo.hProcess );
  41.     CloseHandle( pInfo.hThread );
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment