Reputation: 49
I am trying to create a process in a simple cpp program and want to run another section of code from a different source file in this process. I found the CreateProcess
API for Windows that allows us to create processes but it seems like it only takes exe files for execution. Is there a way to create a process in windows and provide a function etc. to be executed by it similar to threads?
PS: I'm not looking for threads-based solutions since I want to test out a couple of things with processes and shared memory.
Upvotes: 1
Views: 1977
Reputation: 595402
Is there a way to create a process in windows and provide a function etc. to be executed by it similar to threads?
No. But what you can do is have your program run another copy of itself, passing it command line parameters to tell it what to do as needed. You can use GetModuleFileName()
to get the full path to the EXE file of the current process. Then, in your main()
/WinMain()
, if any command line parameters are present, run the appropriate function and then exit, otherwise run your main logic normally.
Upvotes: 3