Carnivorous Plants Website
Carnivorous Plants in the Wilderness
by Makoto Honda
 

  

 

  HOME

 

Visual Studio 2008 Porting Notes   

Last Update: 2011-May-28                                                                  C# / WPF Implementation

========================================================================================

History

M
y home-made CAD software G-System

This CAD program was primarily developed in VC++6.0 on my desktop. My current desktop PC (several years old) is running Windows XP. I have VC++6.0 on it. I also have a new (9-month old) Sony Vaio laptop PC (Centrino, 6GB RAM, 512MB VRAM) running Windows 7. I installed Visual Studio 2008 Professional on both Windows 7 and Windows XP.

Several months ago I tried to port my CAD program to VS2008 (VC++2008) but I encountered a lot of issues.... Finally I built my program on VC++2008, but it hit an assertion and died.... somewhere in the creation of MainFrame, so I gave up....

That meant I could only build on VC++6.0. I wanted to continue my development on Sony, so I tried installing VC++6.0 on my Sony, but I hit a snug: VC++6.0 did not install on Windows 7 -  due to some known problem from MS. So I was left with only my desktop XP to build my CAD using VC++6.0. Once built, G.exe did run OK on my Sony (Windows 7).

Now, on September 1, 2010, I decided to try again.... I wanted to have a good build environment on this Sony laptop, and really wanted to move away from old VC++6.0. The objective is to move completely to VS2008 (and VS2010) - to achieve a clean build on VC++2008 and get rid of VC++6.0 dependency. I assume a move to VS2010 is easy once I move to VS2008, since they are so close in terms of their release dates.

This time, I finally - finally - succeeded in porting my CAD to VS2008 world. I was able to get a clean build of my CAD exe on VC++2008 (on Sony/Windows 7) and it ran OK, no assert failure/Abend. Finally, I do not need my good-old VC++6.0 anymore!

In the month of September, 2010, I achieved the following:

1.  Visual Studio 2008 - Successfully ported the entire program to VC++2008 environment (no more dependency to VC++ 6.0).
2.  Solution/Project setup - Visual Studio 2008 Solution/Project setup has been created.
3.  Release/Debug builds - both release and debug builds have been created.
4.  Automatic DLL Copy - Solution property is set to copy all DLLs to A_Dll-release/debug folder after each build. 
5.  Windows Install - Installation package Setup.msi has been created (Build & Install).
6.  Web Deployment - Setup.msi has been successfully deployed through iNet1000.com download.


========================================================================

Solution Setup in Visual Studio 2008  

Visual Studio uses Solutions and Projects to organize all the files necessary to build an application

1.  In VS2008, it is typical to have a solution that have a number of projects under it.
2.  Typically, one project corresponds to one assembly (DLL or EXE).
3.  I have one project (G.exe) and 11 other projects (*.dll) in my solution.

How to make a project (solution)

1.  In VS2008, File -> New -> Project will make a boilerplate project. A new solution is automatically created to hold the project.
2.  So, create a solution named GS as above. Project named GS will be created under GS, as GS/GS. (GS.sln & GS.vcproj).
3.  Put all my existing VC++6.0 modules (already converted to xxx.vcproj) under GS folder, by adding all projects to this solution:
     File -> Add... -> Existing Project...   Select xxx.vcproj for each existing project.
4.  After all projects (dll & exe) are added, R-click G project (from Solution Explorer) and select "Set as starter project".
5.  R-click GS project and select "Remove" - this was created just to get a boilerplate solution, so we don't need it.
6.  Now, set projects dependencies within the solution:  Project -> Properties. 
     Solution "GS" Property Pages appears, so expand Common Properties and select Project Dependencies..
     Then select each project form the dropdown box and click all dependent projects below.

========================================================================

Incremental Linker Error - internal error

Known problem (hot fix exists). This error is a serious problem for VS2008 - VS2010 fixed this problem.

How to avoid errors....

1.   Bring up VS2008 by double-clicking a project file (xxx.vcproj).
2.   Build -> Build Solution  (The first time seems to be always OK - successful build)
3.   If incremental link error happened, do as below.
4.   Build -> Clean Solution, then Clean ProjectXX, then Build Solution.
5.   If error persists, bring down VS2008 and bring it up again and try.
6.   Sometimes, a few tries are needed to get it right....

My best remedy for this VS2008 incr link problem is to disable this feature for all my projects:
Click Project name node from Solution Explorer and select Properties. In Property Page dialog, Configuration Properties -
Linker - General, and then on the right pane, Enable Incremental Linking - NO.

How to Disable Incremental Linking

1.  R-click Project node from Solution Explorer, and select Properties.
2.  Configuration Properties - Linker - General
3.  On the right pane, Enable Incremental Linking:  NO

========================================================================

My Old Way to Build --- No More!

Right after porting to VS2008 (from VC++6.0), I had 12 solutions (one project per solution) and I had to do the following to build the entire build --- I do not do this anymore because VC2008 Solution will take care of dependencies automatically...

1.  Bring up VC++2008 by double-clicking PPP.vcproj file.
2.  Build -> Clean Solution, then Build -> Clean "project", then Build Solution
     (Other methods produce incremental build errors constantly) LINK : fatal error LNK1000: Internal error during IncrBuildImage
3.  Confirm build is good. == Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ====
4.  In Windows Explorer, copy PPP.h to A_Include folder (replace old).
5.  In Windows Explorer, go to PPP/Debug folder.
6.  Copy PPP.dll to A_DLL folder (replace old).
7.  Copy PPP.lib to A_Lib folder (replace old)

The above steps must be repeated for all projects (solutions) in the order of dependency. The last one is G.exe.
It is best to close VS2008 each time the build is done.

========================================================================

How to build a solution (all projects under it)

Visual Studio 2008 Solution will maintain "dependency" of projects...

1.  Whenever these is a change in Project's *.h include files, you must copy them to A_Include folder.
2.  Because all Projects look at A_Include folder for include files.
3.  Click Visual Studio 2008 / Build->Build Solution. This will automatically build only necessary files.
4.  If you want to build all, click Build->Rebuild Solution or clcik Build->Clean Solution first, then Build Solution.
 

How to copy *dll after each project build automatically

Set project properties to copy the DLL automatically to A_Dll folder.

1.  R-click Project node from Solution Explorer, and select Properties.
2.  Configuration Properties - Build Events - Post Build Event
3.  On the right pane, For command line:
     --->  copy $(OutDir)\$(ProjectName).dll $(ProjectName)\..\..\A_Dll_Debug\$(ProjectName).dll
              (
Paths are relative to the folder in which the project file.vcproj resides.)
     OR
     --->  copy $(OutDir)\$(ProjectName).dll $(SolutionDir)A_Dll_Debug\$(ProjectName).dll
4.  In the above, if you put "echo" in front, the command does not run, but prints out the macro-expanded image in the build window, so you can see how it was interpreted - very useful if an error occurs.

 

How to run the program

After a successful build above, you can run the program as follows:

1.  Copy all *.dll files from A_DLL_Debug or A_DLL_Release, depending on which you built, onto G/Debug or G/Release folder.
2.  Double-click G/Debug/G.exe or G/Release/G.exe.

 
========================================================================

How to make a RELEASE build 

Make sure to add opengl32.lib & glu32.lib as Additional Dependencies for Linker Input

1.  VS2008 - Click Build->Configuration Manager. Set Active solution configuration to Release. Then click Close.
2.  R-click Project node from Solution Explorer, and select Properties.
3.  Configuration Properties - Linker - Input - Additional Dependencies " opengl32.lib glu32.lib "
     (I did this for Debug, but I did not for Release, because I never used Release in VC++6.0.)
4.  I created a separate common folder for release DLL, named A_Dll_Release, and the solution build will automatically copy all DLLs there.

========================================================================

VS2008 Project File ---  ***.vcproj 

Project FileTempering Using Notepad

Background: As a result of converting my VC++6.0 projects into VC++2008, my *.vcproj files (of all projects) have been badly corrupted - Yes, VS2008 is the culprit. This happened during the updating process from *.dsw to *.vcproj by VC++2008. My project dependencies were affected. I experienced many strange dependency issues between debug and release builds also. I could not resolve this problem interactively using VS2008 GUI. So I had to resort to tempering *.vcproj files manually - the *.vcproj file is a text file written in XML and can be edited by Notepad.
--------------------------
The part of the *.vcproj files I am tempering with (very end of the file) is the proper place for each VC2008 project to keep its dependencies. This setion is important - the dependency is specified as:  RelativePath="..\XXX\$(OutDir)\XXX.lib" -- This is the right syntax.

This manual change I made to *.vcproj (using Notepad) has been reflected in VS2008's Solution Explorer pane (as .lib dependencies under each project node).

I also changed my solution properties from VS2008:  Solution Property Pages - Project Dependencies. For one of my projects, I clicked (added) a new dependent project (Depends on:). This added the new dependent lib in Solution Explorer view, and automatically modified *.vcproj file - VS2008 used exactly the same syntax as I did (see above), so I felt totally exonerated!!!!  

Now, instead of adding, I unclicked one project as dependent (Depends on:).  This did not change Solution Explorer view. I wonder if this is a software bug.....  I then removed this entry (lib) from Solution Explorer by R-clicking Remove. Only after have I done so, the corresponding line from this project's vcproj file was deleted.

========================================================================

Deployment  -  Windows Installer (VS2008)

ClickOnce is not available for Windows applications, so I used VS2008 Windows Installer here...

First, select the "debug" configuration and Build-->Clean Solution. Do the same for "release". Then on "release" click Build-->Build Solution.
Now we have only a freshly built solution in release configuration. This is what we are going to package.....
Also, make sure to delete all DLLs from G\release\ folder that you might have copied before to run the program. If we keep these DLLs in G\release folder, this results in dup DLLs to be packaged.

1.  To add a setup project to an existing solution ---
    Open a solution (GS.sln) that you want to deploy. Make sure configuration is set to "release".
2.  R-click the solution in Solution Explorer, Add --> New Project.
3.  In the Add New Project window, select Other Project Types --> Setup and Deployment.
4.  From the right pane, select Setup Wizard. Type a name of the project "G-System" and OK.  Click Next.
5.  Select a radio button : Create a Setup for a Windows Application.  Then Next.
6.  In Choose Project Outputs to Include page, select "Primary output" and "Content files" for all projects (including G.exe).
7.  Click Next. Finish.
8.  Click Application Folder from the left pane (File System on Target Machine). All contents show on the right pane.
9.  R-click "Primary Output from G (Active)"    and Create a short cut...   Name it "G.EXE".
10.  Now, cut and paste this shortcut to User's Desktop (File System on Target Machine), and also...
11.  Add a folder "G-System" under User's Programs Menu (File System on Target Machine)
      and add the same shortcut there. (Must make another shortcut)
12. Now, R-click the setup project from the Solution Explorer and Build. Confirm the build is good.
13. Now, try installing it as a test. R-click the setup and Install (to test)... Make sure to UN-INSTALL the old one first if any!!!!
14. This creates setup.exe and Setup1.msi.  We need to distribute only Setup1.msi to customers.
15. Copy this .msi file somewhere in the Web folder. Then make a link to this file............  That's it.

----------

Some Notes

After step 9 above ....
I got only 9 DLLs, instead of all 11 DLLs under Application Folder (of File System on Target Machine) - ??? - So I copy-pasted 2 missing DLLs from the Windows Explorer \release\ folder and dropped them in Application Folder.  It turned out that even if there are only 9 DLLs shown, the 2 missing DLLs are being packaged during the Build process (as shown in the build trace pane), and therefore, my manual copy (of the 2 DLLs) was not needed to make a good .msi file!

As noted above, if I have all DLLs copied into G\release\ folder, I get duplicate DLLs packaged in my setup... So I thought, if this is a case, I only need to select Primary Output from G, and I do not need to select all Primary Output from individual projects (since I caopied all DLLs under G\release). I tried this scenario to make a setup.msi. However, this did not work and I got an "ElemPipe.dll missing" run time error...  So, selecting Primary Output for all DLL projects are needed (just make sure to delete all DLLs from G\release folder to avoid duplicates).

========================================================================

List of Modifications
Applied During the Port from VC++6.0 to VC++2008

========================================================================

Warnings - Remove them all!!!!

If left, runtime detects this and pop panels!!!

--------
GView.cpp - ln 2218  msgType used w/o initializing

GDate.cpp - ln 2072  pE = NULL;

Element - GElem.cpp  dumValue = 0.0;  (3 places)

Elem1 -GElem1.cpp  in for loop - Add "int" as in for (int i; ...)  (3 places)

ElemCfd - GElemCfd.cpp - ln 5131  - return m;

G - GView.cpp -  ln 1123  if (test) // = true

========================================================================

UINT VS. CSTRING 

G - GView.cpp

OLD:    keyCString += nChar;

NEW:    keyCString += TCHAR (nChar);

========================================================================

Icon for this application

G - int CMainFrame::OnCreate

Somehow, this was failing after porting to VC++2008, so I just skipped this code. This simply disabled the display of the Application Icon... no big deal.

///////////////////////////// Load Icon for mainwindow
HICON hIcon = AfxGetApp()->LoadIcon (IDI_ICON_MAIN);
ASSERT(hIcon);
// AfxGetMainWnd()->SendMessage(WM_SETICON, TRUE, (LPARAM)hIcon);
///////////////////////////// Load Icon for mainwindow
//-------------------------------------------------------------------------- 2010-09-03
// The above code AfxGetMainWnd()->SendMessage(WM_SETICON, TRUE, (LPARAM)hIcon);
// caused Assert failure in VS2008 (VC++2008) so I commented out...
// The only thing this does is to put up my "G" icon for this CAD application, so
// no functionality is lost by commenting this out. Now G-CAD builds & runs on VS2008 !!!
//-------------------------------------------------------------------------- 2010-09-03
 

========================================================================

Visual Studio 2008 - Build Configuration

This must be done for each and every configuration: 32-bit Debug/Release & 64-bit Debug/Release.

1) WHAT TO BUILD

VS2008 – Menu: Build --> Configuration Manager…



2) LINKER INPUT


VS2008 – If some Project (AAA) is dependent on some other Project (BBB), R-Click on AAA from Solution Explorer,
and select Properties...In the left pane, expand Configuration Properties --> Linker --> Input.
In the right pane Additional Dependencies. Click ICON(…) on the right and type in “BBB.lib” and OK.



3) PROJECT DEPENDENCY

VS2008 – If some Project (AAA) is dependent on some other Project (BBB), R-Click on AAA from Solution Explorer,
and select Project Dependencies. Clcik BBB.lib as a dependency.





========================================================================

VS2008 Project Configuration / NEW : 2012-Feb-29

Visual Studio 2008 Project Properties has been changed to forgo "Post Build Event".

1.  Include files do not need to be copied to A_Include folder any more, after any Include file change in any Project. Because... see 2 below.
2.  Each .cpp has #include "..\Element\GElem.h" (example).... Now, both GGlobal.h & Resource.h are under G\ folder.
3.  DLLs do not have to be copied into A_dll folder, so that Post Build Event was disabled (See screen shot below).
4.  So, we do not need A_Include, A_dll_Debug and A_dll_Release folders anymore.
5.  To run after build, hit Ctrl+F5 (no debug) or F5 (debug).








=======================================================================

VS2008 Project Configuration : 2012-April-03

  • This is a basic question about VC++ Project Configuration.

    I have a Solution called X, and two projects under it, Utility & Element. Project Element is dependent on Utility.

    I want to set up the project configuration such that I do not have to move/copy any output files (post-event script) after each build. And I'd like to run by hitting F5 after each build. So I am putting all .dlls & .libs under ...\X\Debug\ folder.

    Project Utility builds fine and Utility.lib & Utility.dll are created at the folder I specified. But when I build Element, I am getting "cannot open .... Utility.lib"
    link error. The linker is searching the folder where "..\Utility" is prefixed to the path I specified in "Additional Library Directories". I do not know why....

    Here is my setup for both Utility & Element projects:

    Configuration Properties->General->Output Directory  $(SolutionDir)$(ConfigurationName)

    Configuration Properties->General->Intermediate Directory  $(ConfigurationName)

    Configuration Properties->Linker->General->Output File  $(OutDir)\$(ProjectName).dll

    Configuration Properties->Linker->General->Additional Library Directories  $(OutDir)

    Configuration Properties->Linker->Input->Additional Dependencies <NONE>

    Configuration Properties->Linker->Advanced->Import Library  ..\$(ProjectName)\$(ConfigurationName)\$(ProjectName).lib


     

 

 

 

 

 

 

 

 

                               

 www.iNET1000.com