We help IT Professionals succeed at work.

Can the CreateProcess() function launch multiple 'functions' within a program rather than multiple exterior <br>executables?

John500
John500 asked
on
Greetings,

I am currently using CreateProcess to launch multiple programs which are exterior to the parent program.  Now however, I want to spawn multiple calls to a function within the parent program.  Is this possible using 'CreateProcess()'?

Below is what I'm using now.  The command line for the 'isql' program which I'm launching takes various parameters to read a file and execute its contents.

string CommandStr = "isql /U /P /S " + ServerName + " /d " + DatabaseName + " /n /i c:\\mydbscript.txt";

sprintf(ComndArray, CommandStr.c_str());
pRC = ExecuteAndWaitForCompletion(ComndArray);

The ComdnArray is then passed to CreateProcess().

The program I'm now working on (completely different) launches a function which establishes a remote connection.  I want to call this function multiple times.  Can CreateProcess() do this?  If so, how would 'CommandStr'
be modified to do this.  Let's call the function connect().

Any idea if multiple streams are an issue here?

Thanks for the help!


Comment
Watch Question

Commented:
Just for understanding your question:
You want to call the function, that establishes a remote connection multiple times to run in parallel?

If I'm right, you should take a look at the thread functions:

CreateThread
ExitThread
ThreadProc
...

Commented:
I am afraid you should look into documentation of your utility program isql. It, and only it, dictates the command line format.

Note that C++ provides much more elegant ways of connecting to external databases, via ADO or ODBC, so that you need not generate external files with SQL scripts, can keep connections alive, etc.

Author

Commented:
lrcuess,

Yes, in its very simplest form, here is the flow:


MakeConnect(string *StrArray)
{
 
  string CommandStr;

  while(!Done){
    //get next value of array and make new CommandStr
    CommandStr = "whatever";  
    CreateProcess(CommandStr);
  }
}
main()
{
  string Strarray[];        // holds node names
  PopulateArray(Strarray);  // get node names
  MakeConnect(Strarray);

  return;
}

alexcohn,
This program has nothing to do with SQL or any databases.  It has to do with a connection to other systems on the network.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.