Many apps of same type opened at a time

Hi,

I am using an MFC application where only one app can be opened at a time.
For example, I built the code and the first time I got name1.exe.
I also rebuilt that code without changing anything and name it as name2.exe.

The problem now is that only one of these two can be opened at a time.
I don't have any experience in MFC programming.
Could you please tell me where should I look for/study to change it into an app that can be opened simultinously.
Check the module names.
Hi,
Could you talk a little bit more detail?
My app now is something like IDM (Internet Download Manager). Only one app runs at a time.
I want it to be like Notepad or Calculator. We can open many apps at a time.
Please tell me where should I look for in the code structure?
Last edited on
Could you tell me the term I should search for?
I don't know how to search it?
That is not multiple view document because I want something like notepad. I can run two notepads at a time.
Is it multi-thread programming?
It is not multi-thread programming.

The keyword to search for would be "instance". You want the program to be able to have multiple instances running at once.

What you want is actually the default behavior for programs. Your program should be doing this on its own. You actually have to do work to make it so a program can only have 1 instance at a time.

MFC must be doing something differently. I don't have much experience with MFC, but I'm assuming you used some kind of wizard when you created the program. Perhaps go back in that wizard and look around for an option to enable multiple instances.
Well, thanks for the reply!
I searched for the term and there are many articles about this.
I will read up and ask for help if there is any problem.

Can we see some code? Is your application calling "CreateSemaphore()" or any other named object? The kind of "effort" that Disch describes is generally done with either a named object in the global namespace or it's done with a lock file, the later method is much easier to notice.
Sorry, I wish I could but I don't have the permission to post the code.
However, I think the problem is from CreateMutex() in InitInstance().

Running one instance of a Windows application was easy in WIN16 because each instance received the previous instance of the same application. If you wanted to restrict multiple instances, you just checked if the previous instance was not null, and terminate.

WIN32 behaved differently, the previous instance is always null. Each Windows executable has a module name. This is true for DLLs and EXEs. One way to restrict running is to check if your module is already running and terminate if it is.

If you've copied a program that does this and changed the final executable name but not the module name, you'll only be able to run one of these--kinda like what you have now.

So check the module names and change that too. It's specified in the .DEF file.
Hello again!
I checked InitInstance() function and found CreateMutex(). After deleting the CreateMutex() function, I can open many instances now!
I work like a charm.
I have another question, hope you could give your opinion.

For example, my app does some tasks.
If I open only one instance, it take s1 seconds to complete the task.
How about the time to complete the tasks if I open two or three instances and do the same things as one above?
Does the time double or 3 times of the first case?
All's well that ends well.
Hi,
All's well that ends well.

Could you explain more? Sorry I am not an English native speaker.
Topic archived. No new replies allowed.