Is there a way to have multiple main in the Visual studio? - visual-studio-2010

Is there a way to have multiple main in the project and each main can be executed?

If you want to multi-thread your application, you should look into thread libraries. Otherwise, there is no way you can have multiple main functions. The compiler stores the main function as the first set of instructions to be executed. If you are just running one thread, you can't simultaneously execute two sets of the same instructions. What exactly are you trying to do?

Related

My Perl script starts too slowly, and includes many modules - can I precompile it?

I have a Perl script, that includes a few custom Perl modules.
I have profiled the script using Devel::NYTProf, and I can see that including these Perl modules has a cost that I would like to minimize.
I have installed PAR::Packer and compiled my script to make it stand alone, but it does not include the custom Perl modules.
Any suggestions?
Edit :
I need to precomplie the script so that i does not include the compilation overhead every time it is evoked.
If some of the packages you import are not needed at startup, change use calls to require and move them to the places in your code where the packages are needed (so you import them when they are needed, not necessarily at startup). Depending on how complex your program is, it could be a lot of work to figure out what calls can be changed without breaking your program or affecting its behavior.
Borodin's daemon suggestion is a good one, too. Start a skeleton of your program that loads the necessary packages and waits for something to invoke it (maybe set up a socket connection or a signal handler). Then when it is time for your program to run, fork it and call some &main subroutine that starts the useful part of your program.

debugging a dynamically loaded executable

I've been handed an application to support, and I'm trying to figure out how to do it. I do have the source, and can make some changes, but I obviously don't want to completely change the architecture of the application.
The app is in a VS2010 solution composed of 9 different projects. The main one is a Windows Form application, but it spins off others in other threads.
Here's the difficulty. Even though the different projects are parts of the same solution, they are separate executables, not DLLs. When the main program starts one of the other projects, it does so by creating a new process, setting the filename of the executeable, the startup arguments and other assorted parameters into the process.StartInfo object, and then calls process.Start().
How can I set breakpoints and debug subordinate executables? I can't attach to them until they are loaded, but they don't get loaded until process.Start() is called, and by then it's too late. Is there a method call I can insert into the main program to get it to load the executable (so I can set breakpoints in it) before it actually begins execution?
Thanks.
Are you able to recompile the other executables? If so, have you tried putting DebugBreak in suitable places? (or _asm int 3).
You can't load the process (usefully), since by definition it will be run in a different addres space from the one you are debugging before it starts.
One simple solution could be adding a call to DebugActiveProcess function to the "main" function of every process which participates in your application.

how to call winmain function through a main function

I am using dev c++ and i need to call a function which has some butons and edit boxes created using windows.h through another program which uses graphics functions and both files exist in a project and i am unable to do it..can any one help me please...
From what I gather, you have a function that creates some GUI components and needs to be called from two different programs. If this is the case, one option is to create a separate .DLL project that makes a run-time library that can be shared with the other two programs.

Programming experiments

I frequently code numerous experiments to test various algorithms, libraries, or hardware. All code, dependencies, and output of these experiments need to be annotated and saved, so that I can return to them later. Are there good common approaches to this problem? What do you do with your experiments after running them?
At a prior job we had a project in SVN called Area51 where people would write test code. The rules were
create a package namespace
start via a public static void main
add comments via javadocs
leave the project in a compilable state
the project can never be a dependancy of other code
On a three person team this worked out ok. We could put "what if" code there to share and it was easy to run it via ide or command line
When I do these, they are usually project specific, so they go in a subdirectory of the project (usually named "Investigations" in my case). This gets checked into the version control system with everything else.
Results (where appropriate) go into the same subdirectory of "Investigations" as the code used to produce the results.
http://subversion.tigris.org/
I just have a folder which I call OneOffCode
This is a folder of just code I have written either learning a new technology trying to prove a concept etc. . . This is non production code.
I usually back it up to a jump drive and move it with me from Job to job, or computer to computer.
I'm usually switching between C# and C++. So, I have a Test console application for C# and C++ in a "Sandbox" location, under source control. The console applications are both setup the same way where there is a Main which calls the test that I'm trying at that time. When I'm done I keep the old methods and comments and just clear out the Main when the next test comes about.
I don't know if it is the best, but after it is setup then it is pretty quick to get in, get the answers, get out and have it all saved for the next time.

How to programmatically cancel an embedded MsBuild build

I'm embedding MSBuild directly into a more complex build tool. The relevant code looks roughly like this:
// assume 'using Microsoft.Build.BuildEngine;'
Engine e = Engine();
BuildPropertyGroup props = new BuildPropertyGroup();
props.SetProperty( "Configuration", Config.BuildConfig );
e.BuildProjectFile( projectFile, new string[] { "Build" }, props )
My question is how to cancel this build once it's started, without doing something drastic like terminating the thread. Also, if the project being built is a C++ project, the build will involve at least one sub-process, so canceling the thread isn't even going to really cancel the build.
I don't see any cancel method on the Engine class - does someone know of a way?
This question has come up a few times on the MSDN boards, and unfortunately I haven't seen any other way, apart from terminating the thread. Sadly, in this case, terminating the thread isn't really drastic with it being the only real option.
On a random side note, I am not sure to what extent you are using MSBuild with what you are doing currently. Just wanted to recommend taking a look at the MSBuild Extension Pack on Codeplex if you work with MSBuild on a regular basis.
I had done something similar by running msbuild from command. This starts a process which you could terminate.
From my experience, it is far easier and flexible to manipulate the project files using xml tools and then execute msbuild than it is to programmatically configure your projects the way you have described. It is also more manageable.
It appears is that there's no official way to do this.
For C# builds it's not a huge deal, since they are typically really fast. The best workaround I've come up with for C++ builds is to locate the child processes that are created by the VC build process and terminate them, which stops the MSBuild build. This can be done using a Toolhelp32 snapshot, something like this (omitting P/Invoke garbage):
CreateToolhelp32Snapshot( ToolHelp.SnapshotFlags.Process, 0 );
From here you can determine the parent/child relationship between processes and find the processes spawned by the app that's invoking MSBuild.

Resources