calling exe from in a Dll? Help the poor VB guy!

This is a discussion on calling exe from in a Dll? Help the poor VB guy! within the C++ Programming forums, part of the General Programming Boards category; I am a strictly VB programmer and this C stuff is driving me crazy right now! All I need to ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    3

    calling exe from in a Dll? Help the poor VB guy!

    I am a strictly VB programmer and this C stuff is driving me crazy right now!

    All I need to do is create a simple DLL that will start an executable when a function is called. However I do not have any idea what C command to call to start an executable. In VB, it would be shell... could someone enlighten me to the C++ equilivant?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Best Bet...

    Code:
    HINSTANCE ShellExecute(
        HWND hwnd, 
        LPCTSTR lpOperation,
        LPCTSTR lpFile, 
        LPCTSTR lpParameters, 
        LPCTSTR lpDirectory,
        INT nShowCmd
    );

  3. #3
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    try the _spawn family of commands. For instance _spawnl.

    int _spawnl( int mode, const char *cmdname, const char *arg0, const char *arg1, ... const char *argn, NULL );

    You could also look into CreateProcess but I recomend _spawn.

    /* Edit */

    Beaten by Fordy as I looked up the spawn syntax. I still recomend _spawn over ShellExecute as its more portable. ShellExecute will run files of other types than exe, however. Depends what you're after.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    3
    that is completly foreign to me...

    say i want to start c:\email.exe
    where would I plug this in? Can I just copy this code into my function and expect it to run?

    Right now I am at square 1... i have a clean slate..

    int public emailfunction()
    {
    <need stuff here>
    }


    once finished i it will be complied to a DLL and called from within an IBM content manager client.... sadly this does not support VB Dll's which i know :-)

  5. #5
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    Well, I ripped the example from my help files but I suggest you look up the function to fully understand what arguments its taking. If you dont have a help file for some reason you could look here.


    Code:
    /* SPAWN.C: This program accepts a number in the range
     * 1-8 from the command line. Based on the number it receives,
     * it executes one of the eight different procedures that
     * spawn the process named child. For some of these procedures,
     * the CHILD.EXE file must be in the same directory; for
     * others, it only has to be in the same path.
     */
    
    #include <stdio.h>
    #include <process.h>
    
    char *my_env[] =
    {
       "THIS=environment will be",
       "PASSED=to child.exe by the",
       "_SPAWNLE=and",
       "_SPAWNLPE=and",
       "_SPAWNVE=and",
       "_SPAWNVPE=functions",
       NULL
    };
    
    void main( int argc, char *argv[] )
    {
       char *args[4];
    
       /* Set up parameters to be sent: */
       args[0] = "child";
       args[1] = "spawn??";
       args[2] = "two";
       args[3] = NULL;
    
       if (argc <= 2)
       {
          printf( "SYNTAX: SPAWN <1-8> <childprogram>\n" );
          exit( 1 );
       }
    
       switch (argv[1][0])   /* Based on first letter of argument */
       {
       case '1':
          _spawnl( _P_WAIT, argv[2], argv[2], "_spawnl", "two", NULL );
          break;
       case '2':
          _spawnle( _P_WAIT, argv[2], argv[2], "_spawnle", "two", 
                   NULL, my_env );
          break;
       case '3':
          _spawnlp( _P_WAIT, argv[2], argv[2], "_spawnlp", "two", NULL );
          break;
       case '4':
          _spawnlpe( _P_WAIT, argv[2], argv[2], "_spawnlpe", "two", 
                    NULL, my_env );
          break;
       case '5':
          _spawnv( _P_OVERLAY, argv[2], args );
          break;
       case '6':
          _spawnve( _P_OVERLAY, argv[2], args, my_env );
          break;
       case '7':
          _spawnvp( _P_OVERLAY, argv[2], args );
          break;
       case '8':
          _spawnvpe( _P_OVERLAY, argv[2], args, my_env );
          break;
       default:
          printf( "SYNTAX: SPAWN <1-8> <childprogram>\n" );
          exit( 1 );
       }
       printf( "from SPAWN!\n" );
    }
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    3
    i have the functions worked out... but it seems like the DLL is not exposing them to the other appliation... here is my source is anyone has the time to look.

    Thanks so much... I hope some time I can return the favor.

    http://web.njit.edu/~dkm3/CallEXE.zip

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to monitor exe and dll interactions?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 10-26-2007, 04:22 AM
  2. Calling a DLL
    By jamez05 in forum C++ Programming
    Replies: 1
    Last Post: 01-05-2006, 10:13 AM
  3. Troubles Calling a DLL
    By jamez05 in forum C++ Programming
    Replies: 2
    Last Post: 12-02-2005, 11:00 AM
  4. Calling a VB DLL w/ forms from C++ DLL
    By UW_COOP in forum C++ Programming
    Replies: 8
    Last Post: 06-30-2003, 08:04 AM
  5. a british question/joke
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 06-02-2002, 01:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21