I'm having a bit of difficulty figuring out how to create a new process in Windows for each iteration of the same function. I've read the CreateProcess documentation, but it seems as though it wants a filepath instead of a function as a parameter, and I'd rather not create a separate file just for my function (unless that would be the recommended best practice). Take for example the below trivial code:
#include <iostream>
#include <vector>
#include <windows.h>
using namespace std;
int foo(int fooParameter)
{
return (fooParameter + 1);
}
int main(void)
{
vector<int> numList;
numList.push_back(1);
numList.push_back(2);
numList.push_back(3);
for (int i = 0; i < numList.size(); i++)
{
cout << "query: " << numList[i]
<< "\tcount: " << foo(numList[i])
<< "\tpid: " << /*pid <<*/ endl;
}
return 0;
}
I would like to create a new process for every time foo() is run and print the result of foo in addition to the process id of the new process created. Is CreateProcess even the right way to go about this? I'm only using it because it was the only fxn mentioned in our class example. I'm very new to using the WINAPI, and pretty much all the examples I've seen were in Linux using fork(), which is obviously out the question here.
Any recommendations on how to best implement this are appreciated!