views:

252

answers:

5

I have a VS generated C++ Win32 DLL project. It has the following files:

stdafx.h targetver.h myProject.h dllmain.cpp myProject.cpp stdafx.cpp

I can remove targetver.h, and merge dllmain.cpp into myProject.cpp. What more can I do to get the simplest file structure, preferably one file. I need to dynamically emit this code file and build it into a Win32 DLL.

A: 

IIRC, myProject.h and myProject.cpp both contain an example of an exported class. You can easily delete those.

stdafx.cpp and stdafx.h are used for the standard precompiled header file. If you turn off the setting that requires a precompiled header, then those files won't be necessary, either.

Andy
+1  A: 

In addition to what Andy said, you can merge the myProject header and implementation files as well with dllmain.cpp. But why not just keep these files and create the vsproj file at runtime?

dirkgently
+1  A: 

Or you could just create an empty project.

+1  A: 

If you want a minimalistic file structure, you could just create the files yourself. Start an empty project, or delete all the files. Heck, just make a folder, write main.cpp, and compile it from the command line with cl.

Few IDEs really try to minimize files like you're trying to -- but when you create the project, you can cut back a little: stdafx.[h, cpp] are for precompiled headers, which you could disable when creating the project.

That said, I don't really see the value in minimizing the amount of source code in a compiled language project -- it's not going to have a meaningful impact on the number of output files/dlls and, properly used, using more files only helps your code's clarity.

ojrac
A: 

You could #include your generated file into a existing multi-file project. That way you can have a shell of a complicated project and only emit something smaller, like a simple function.

For example:

#include <system_stuff>

void main()
{
   Go();
}

#include "generated_file_that_has_method_go.cpp"

void other_code()
{
}
Aardvark