I still see no question in this post as you explain by yourself what you need to do. Do you just need confirmation? You just need the technique "Divide and Conquer".
1) First, write an application abc.exe accepting two parameters,
argv[0]
for function name,
argv[1]
for file name. Always validate parameters. First, validate that the user really supplied two parameters using
argc
, than validate that a function and the file exists. How to validate that a function exists and select one? I'm afraid to say, by some long
if
statement. This is C++, and your whole idea is pretty bad, I must say, that's it. In this application, read the file. I hope you know how to read the file having its name. Write some other applications using the same schema for parameters, file type, etc.
2) Write the application xyz.exe accepting three parameters:
argv[0]
for child application executable name,
argv[1]
for function name,
argv[2]
for file name. Again, validate all parameters as I explained above. Additional validation is existing of the application passed as
argv[0]
.
3) Run the application passed as
argv[0]
, pass two other parameters as the parameters of child application. The parameters
argv[1]
and
argv[2]
in xyz.exe will become the values for parameters
argv[1]
and
argv[2]
in the child application. How to run it? It depends on your platform. For example, on Windows, this will be the call to Windows API
CreateProcess
,
http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx[
^]; this is a simple code sample:
http://goffconcepts.com/techarticles/development/cpp/createprocess.html[
^]. On other platforms, you will always find some API like
fork
(like on Linux), "OS", etc.
Is that all clear? Perhaps I really don't understand what could cause any difficulties.
Now, I mentioned that this approach is pretty bad. Why torturing yourself with all that string values and validations and getting a lot of errors to handle, not even mentioning possible bugs? Better use DLLs or Shared Libraries (which is essentially the same).
—SA