Advertisement
CODE_TOLD_FAST

02/M.C11

Jan 19th, 2020
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.62 KB | None | 0 0
  1.  
  2. //:         VIDEO: https://www.youtube.com/watch?v=kSsQtozz4iA
  3. //:       CHANNEL: CODE_TOLD_FAST
  4. //: PASTEBIN_NAME: 02/M.C11
  5.  
  6. //: Summary: Main program that calls sub program.
  7.    
  8. #include <windows.h>
  9. #include <stdio.h> //:for: printf(...)
  10.    
  11. typedef    /////////////////////////////////////////////////////
  12.     int  //:<<<<<<<<<<<<<<<<<<<< Func Pointer Return Type  ://
  13.     (*PFN_ShellExecuteA)( //:<<<<< Func Pointer Name <<<<<<< ://
  14.     //[FuncPointer:Args___________]/////////////////////////////
  15.     /**/      void*   hwnd         //  
  16.     ,   const char*   lpOperation  //  HINSTANCE == void*
  17.     ,   const char*   lpFile       //       HWND == void*
  18.     ,   const char*   lpParameters //     LPCSTR == const char*
  19.     ,   const char*   lpDirectory  //        INT == int
  20.     ,          int    nShowCmd     //  
  21.     //[___________________________]/////////////////////////////
  22.     );//////////////////////////////////////////////////////////
  23. struct
  24.     ARG_ShellExecuteA{
  25.     /**/      void*   hwnd         ; //: IDENTICAL_TO_TYPDEF ://
  26.     /**/const char*   lpOperation  ; //: IDENTICAL_TO_TYPDEF ://
  27.     /**/const char*   lpFile       ; //: IDENTICAL_TO_TYPDEF ://
  28.     /**/const char*   lpParameters ; //: IDENTICAL_TO_TYPDEF ://
  29.     /**/const char*   lpDirectory  ; //: IDENTICAL_TO_TYPDEF ://
  30.     /**/       int    nShowCmd     ; //: IDENTICAL_TO_TYPDEF ://
  31.     };
  32. ////////////////////////////////////////////////////////////////
  33.  
  34.     int main( void ){
  35.     printf("[M.C11:BEG:main]\n");
  36.        
  37.            
  38.     //:Load the DLL file containing ShellExecuteA:
  39.  
  40.     void* lib = LoadLibraryA( "Shell32.dll" );
  41.     if(NULL==lib){
  42.         printf("[UnableToLoadDll:Shell32]\n");
  43.         exit(666);
  44.     };;
  45.            
  46.     //: Get Function Pointer To ShellExecuteA:
  47.     //:------------------------------------://
  48.     //: TYPE: PFN_ShellExecuteA
  49.     //:  VAR: pfn_ShellExecuteA
  50.     //:------------------------------------://
  51.  
  52.     PFN_ShellExecuteA
  53.     pfn_ShellExecuteA=(
  54.    (PFN_ShellExecuteA)GetProcAddress( lib,
  55.        "ShellExecuteA"
  56.     ));;
  57.     if(NULL==pfn_ShellExecuteA){
  58.         printf("[ShellExecuteA:NULL]");
  59.     };;
  60.    
  61.     //:------------------------------------://
  62.            
  63.     //:Create Argument List:
  64.     const char* lpParameters=(
  65.         "ARG01"
  66.         " "
  67.         "ARG02"
  68.         " "
  69.         "ARG03"
  70.         "\0" //:Extra null terminator to be safe
  71.     );;
  72.            
  73.     //:Function Call:
  74.  
  75.     //| If the function succeeds, it returns a value         |//
  76.     //| greater than 32. If the function fails, it           |//
  77.     //| returns an error value that indicates the cause      |//
  78.     //| of the failure. The return value is cast as an       |//
  79.     //| HINSTANCE for backward compatibility with 16-bit     |//
  80.     //| Windows applications. It is not a true HINSTANCE,    |//
  81.     //| however. It can be cast only to an int and compared  |//
  82.     //| to either 32 or the following error codes below.     |//
  83.     //[ SOURCE: MSDN article on ShellExecuteA                ]//
  84.     struct ARG_ShellExecuteA  A = { 0 };
  85.     int res = pfn_ShellExecuteA(
  86.         ( A.hwnd        = NULL         ) //:No window
  87.     ,   ( A.lpOperation = "open"       ) //:open/execute
  88.     ,   ( A.lpFile      = "S.exe"      ) //:Program To Run
  89.     ,   ( A.lpParameters= lpParameters ) //:Argument List
  90.     ,   ( A.lpDirectory = NULL         ) //:Use Program's Dir
  91.     ,   ( A.nShowCmd    = 0            ) //:Not windowed program
  92.     );;
  93.  
  94.     if( res <= 32 ){
  95.         printf("[ShellExecuteA:FAIL]");
  96.         fflush(stdout);
  97.         exit(666);
  98.     };;
  99.  
  100.     printf("[M.C11:END:main]\n");
  101.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement