sirdanman10 0 Newbie Poster

Does anybody know a good tutorial on programming applications with multiple entry points in C++? I am designing an application in MSVC 2008 Express that will interface with an AS/400 system and process scripts to either feed data, extract data by reading the screen, or do custom tasks. I was planning that it could be a stand-alone program where the user loads a script and it runs, or it could be a liason between Excel and the AS/400 via COM. I was also thinking that double-clicking a file (say, on the desktop or in Windows Explorer) could add the file to the process queue, and that if the program is open I could also add a file to the queue by putting the file into a particular directory. (I think I have that part covered by the filesystemwatcher class.)

So, my questions are thus:
1. How can I design a program where if the user clicks on the icon while the program is already running, the spawned copy will recognize that the program is already running and transfer control to a particular routine in the original instance? I know it can be done because there are programs that do it. What I am asking is, in effect, how do I make it so that if the user double-clicks on an icon while the program is running, instead of opening a new instance it simply brings the user to the instance already running? (And still checks the parameters being passed in, so like if I drag a file into the icon it will be recognized?)

2. If I program a COM library of functions for Visual Basic for Applications to use to control basic tasks in the program remotely, such as querying which file is being processed or changing the priority of a particular task to be run, how do I work it so that if the program isn't running yet and Visual Basic encounters a COM command, it doesn't crash? I was thinking of making a "check if the program is open" command... which I suppose would need the program to be invoked, but only the COM portion, and return a status of if the program is running or not, then close. (Or would I want it like a TSR that would keep running in the background to handle other such events?) How would I do that?

I can see that in any case there will have to be some sort of central holding place in memory to show if the program is open or not... but if I used the registry then if the program doesn't properly shut down it will still show as being open, even after shutting down the computer and rebooting. And there would probably also have to be somewhere a pointer or handle of some sort to the original thread.

Any ideas?

Thanks.
-Dan