CAD System Web Site - Computer Aided Design Software
i NET1000.COM
by Makoto Honda
 
 

  

 

  HOME

 

Revisiting Visual Studio 2008 - New 2012-May   

Last Update: 2012-November-01                                                                 

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

    List of "Done" Items ---  The Original VC++ Project Revived   -- Progress Report                                         

  2012-June-08 Added an image in a dialog.
  2012-June-06 Added a Tab Control in Tools-Customize Dialog box.
  2012-May-23   VC++ 64-bit now being supported.
  2012-May-11   New VS2008 Solution created anew (to removed a strange link error problem):
                             New configuration properties / New solution directory / Win32+x64 / Debug+Release.
                             Unicode support / CString support / x64 support / F5 to run / No post event processing
 

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

History

Weird Link Error Problems due to Configuration Properties Setup...

Conclusion - something was wrong with vcproj files of all projects.... since they were auto-modified by VS2008.

Solution - I have to create a new 2008 VC++ Solution/Project (will support UNICODE and x64....).

 

How to Create a Brand New Solution/Project in VS2008

1.   Open VS2008 and Create a brand new solution/project ...... Choose MFC Application (MDI)
      File - New - Project to make a boilerplate solution/project. Name the solution "GS" and the project "G"

2.   In VC++, add all Projects to the Solution (File - Add - New Project...)  Use "Project_xxxx" naming convention... 
      Must be "MFC Extension DLL" project type.
      Do not choose Add Existing Project... because .vcproj file will be corrupted during VS2008 conversion.

          G.exe 
          Project_FMcfd.dll
          Project_FMediting.dll
          Project_FMelement.dll
          Project_FMbase.dll
          Project_Data.dll
          Project_ElemCfd.dll
          Project_Elem1.dll
          Project_Element.dll
          Project_Utility.dll


3.   In VC++, set Project Dependency... Project - Project Dependencies...

4.   In Windows Explorer, copy all (existing) h/cpp to the respective project folders of this new Solution.
          ----- Don't forget the following:
          MainFrm,
          ChildFrm,
          G/G.rc, 
          G.h/cpp,
          GDoc.h/cpp,
          GView, GView2, GView3,
          GFrame, GFrame2,
          myGLswitch.h, all Stdafx.h,
          G/Resource.h,
          G\GGlobal.h
          G\res\ ... all icons, toolbar icons

5.   Then in VC++, for each Project, Add existing item... (Header & Source folders)

6.   Stdafx.h - must contain #include "..\G\Resource.h" &

          #include <gl\gl.h > // OpenGL
          #include <gl\glu.h > // OpenGL
        
//#include <gl\glaux.h > // OpenGL
          #include "myGLswitch.h" // Logical flags

7.   In VC++, Build - Configuration Manager...  Click all projects to build

8.   In VC++, Build - Configuration Manager... Create "x64" --> Active Solution Platform: <new> Type or Select New Platform: "x64"

9.   Windows Explorer -- File Structure: 

     2012-05-07 xxx \ GS \ G
                                     \ Project_FMcdf
                                     \ Project_FMediting
                                     \ Project_FMelement
                                     \ Project_FMbase
                                     \ Project_Data
                                     \ Project_ElemCfd
                                     \ Project_Elem1
                                     \ Project_Element
                                     \ Project_Utility
                                     \ Win32 \ Debug ---------------- all .dlls & .libs
                                                    \ Release  ------------- all .dlls & .libs
                                     \ x64 \ Debug  ------------------- all .dlls & .libs
                                               \ Release  ----------------- all .dlls & .libs
                                     \ GS.sln


10.   In VC++, set G as "Set as startup project"
 

VS2008 Project Configuration Properties: 2012-May-17

  • This is my VC++ Project Configuration common to all projects (both Win32 & x64 and Debug & Release):

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

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

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

    Configuration Properties->Linker->General->Enable Incremental Linking  No (/INCREMENTAL:NO)

    Configuration Properties->Linker->General->Additional Library Directories    <NONE>

    Configuration Properties->Linker->Input->Additional Dependencies   opengl32.lib glu32.lib

    Configuration Properties->Linker->Advanced->Import Library  $(TargetDir)$(TargetName).lib
     


     

VS2008 64-bit Change Items.....

   UINT_PTR

 
   CWnd::OnTimer ( UINT_PTR nIDEvent )

 

VS2008 Change Items.....

CString / MFC

 
   CString is a macro that expands to :
          CStringW  .............. #ifdef UNICODE
          CStringA   .............. #else

      By default, VS2008 defines UNICODE so the code CString s = "aaa" compiles to :
          CStringW s = "aaa";  // compile error

      Correct syntax :
          CStringW s = L"aaa";   // unicode string literal 
          CStringA s = "aaa";      // non-unicode string literal
          CString s = _T("aaa");  or TEXT("aaa"); 

     _T is a macro which expands to :
         _T("aaa")  ------>  L"aaa"  ...... #ifdef UNICODE
         _T("aaa")  ------>  "aaa"  ........ #else

     TEXT or _T  .... makes the string literal "wide" (when Unicode defined) or "narrow" (if not)   

     Best to write Windows applications as Unicode.... Use a TCHAR string literal to be  generic.

     TCHAR becomes :
        wchar_t  .....  #ifdef UNICODE
        char  ..........   #else

     CString YCHAR constructor explicit

     XCHAR = wchar_t  ..........  UNICODE characters
     YCHAR = char .................  ANSI/MBCS characters

     VC++ compiler supports both as native data types.

     EXAMPLES:

       SystemFeedbackMessageFLOAT1 (_T(" Zoom lens angle defined (degrees) ="), m_value1KEY);
       SystemFeedbackMessage1 (_T(
"Multi points created"));
       str.Format (_T(
" Error System Feedback MSG"));
       str.Format (_T(" Value is  %d\n"), n);
 

std::string

1.  Convert:   char* à  std::string

const char* s = ”ABC”;
std::string str (s);

2.  Convert:   std::string
à char*

std::string str;
const char* s = str.c_str();

3.  Convert:   std::string
à “writable” char

std::string str;
char* my_char = new char [str.size() + 1];
std::copy (str.begin(),str.end(), my_char);
my_char [str.size()] = '\0'; // don't forget the terminating 0
Use ---- use my_char ---
delete[] my_char; // Must free the string after finished using it

4.  Convert:   std::string à wchar

std::string str;
std::wstring wstr = std::wstring(str.begin(), str.end());
//Then get the C string:
const wchar_t* my_wchar = wstr.c_str();

5.  Convert:   std::wstring
à wchar

std::wstring wstr = ( L”John Smith”);
const wchar_t* my_wchar = wstr.c_str();
 

Marshaling / CLI

1.  Convert:   Managed code à Native (un-managed)

String ^ m_sManaged;  // member data…
if ( m_sManaged && m_sManaged ->Length > 0 )
{
  char sNative [TEXT_MAX];
  char* temp = (char*)(Marshal::StringToHGlobalAnsi(m_sManaged)).ToPointer();
  int len = strlen (temp);
  strncpy (sNative, temp, len);
  sNative [len] = 0;
  Marshal::FreeHGlobal(IntPtr((void*)temp));
  // Now, use… sNative;
}

2.  Convert:   Native (un-managed) à Managed code

std::string strNative; // . . . .
std::wstring wstr = std::wstring (strNative.begin(),strNative.end());
//Then get the C string:
const wchar_t* my_wchar = wstr.c_str();
String ^ m_sManaged = gcnew String (my_wchar);


How to find out which Project a particular .cpp belongs to...

      In VS, make that .cpp active.  Then Project menu - R-click.  The last item shows XXX properties. 
      "XXX" is the Project name.
 

enum (IDD = IDD_MY_DIALOG);

      In VC++, we can define a dialog template in the resource editor. How do we associate our CDialog-derived class with this dialog template id?
      It is done by the CDialog constructor during the CMyDialog class's constructor chaining:

      Suppose the template id of my dialog in the resource editor is IDD_MY_DIALOG, 

      enum (IDD = IDD_MY_DIALOG);

      CMyDialog :: CMyDialog (CWnd* pParent)
           : CDialog (CMyDialog :: IDD, pParent) { }


How to create Tab Control in MFC

Create a dialog and place a tab control somewhere in it in the dialog. This tab control has a few tab pages.
Using VC++ Resource Editor, create a "Picture Control" or "Tab Control" in the existing dialog to reserve a space for this tab control.
Name it "IDC_MY_TAB_CONTROL" in the Property Pane of this control.
Also, using Resource Editor, create a dialog for each of the tab pages and name the id of the dialog template as IDD_MY_PAGE_1,2,3,...

Dialog : CMyDialog ---------------------- derived from -> CDialog
Tab     : CMyPropertySheet ---------- derived from -> CPropertySheet
Pages : CMyPropertyPage1,2,3 ---- derived from -> CPropertyPage

<<  MyDialog.h >>

class CMyPropertySheet;
class CMyPropertyPage1;
class CMyPropertyPage2;

//////////////////// PROPERTY SHEET /////////////////////////////////////////////////////////
class CMyPropertySheet : public CPropertySheet
{
public:
CMyPropertySheet();
// standard constructor

//{{AFX_DATA(CMyPropertySheet)
/////
enum { IDD = IDC_MY_TAB_CONTROL };
//}}AFX_DATA

CMyPropertyPage1* m_page1;
CMyPropertyPage2* m_page2;

//{{AFX_VIRTUAL(CMyPropertySheet)
protected:
// virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

//{{AFX_MSG(CMyPropertySheet)
virtual BOOL OnInitDialog();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

/////////////////////// DIALOG //////////////////////////////////////////////////////
class CMyDialog : public CDialog
{
public:
CMyDialog (CWnd* pParent = NULL);
// standard constructor

//{{AFX_DATA (CMyDialog)
enum { IDD = IDD_MY_DIALOG };
//}}AFX_DATA

// Tab Control & Tab Pages
CMyPropertySheet    m_myTab;
CMyPropertyPage1* m_myPage1;
CMyPropertyPage2* m_myPage2;

//{{AFX_VIRTUAL(CMyDialog )
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

//{{AFX_MSG(CMyDialog )
virtual BOOL OnInitDialog();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

//////////////////////////// PROPERTY PAGE 1 2 3 /////////////////////////////////////////////////
class CMyPropertyPage1 : public CPropertyPage
{
public:
CMyPropertyPage1();
// standard constructor
//{{AFX_DATA(CMyPropertyPage1)
enum { IDD = IDD_MY_PAGE_1 };
//}}AFX_DATA

//{{AFX_VIRTUAL(CMyPropertyPage1)
protected:
// virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

///{{AFX_MSG(CMyPropertyPage1)
virtual BOOL OnInitDialog();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////

<<  MyDialog.cpp >>

///////////////////// DIALOG ////////////////////////////////////////////////////////
CMyDialog ::CMyDialog  (CWnd* pParent /*=NULL*/)
     : CDialog (CMyDialog::IDD, pParent)
{
    
// Create pages
     m_myPage1 = new CMyPropertyPage1();
     m_myPage2 =
new CMyPropertyPage2();
     m_myPage3 =
new CMyPropertyPage3();
}

BEGIN_MESSAGE_MAP (CMyDialog, CDialog)
//{{AFX_MSG_MAP (CMyDialog)
ON_BN_CLICKED(IDC_BLUE_LIKE, OnBlueLike)
ON_BN_CLICKED(IDC_PURPLE_LIKE, OnPurpleLike)
//}}AFX_MSG_MAP

ON_STN_CLICKED (IDC_MY_TAB_CONTROL, &CDlgCustomize::OnStnClickedTabPic)
END_MESSAGE_MAP()

BOOL CMyDialog::OnInitDialog()
{
     CDialog::OnInitDialog();

     // Add Tab Pages...
     m_myTab.AddPage (m_myPage1);
     m_myTab.AddPage (m_myPage2);
     m_myTab.AddPage (m_myPage3);

     // Create Tab Control...
     m_myTab.Create (this, WS_CHILD | WS_VISIBLE | WS_TABSTOP);
     m_myTab.ModifyStyleEx (0, WS_EX_CONTROLPARENT);
     m_myTab.ModifyStyle (0, WS_TABSTOP);

     // Display Tab Control...
     CRect rec;
     GetDlgItem (IDC_MY_TAB_CONTROL)->GetWindowRect (&rec);
     ScreenToClient (&rec);
     m_myTab.SetWindowPos (NULL, rec.left, rec.top, 0,0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);

     return true;     
}

////////////////////////// PROPERTY SHEET ///////////////////////////////////////////////////
CMyPropertySheet::CMyPropertySheet()
     : CPropertySheet() { }

BOOL CMyPropertySheet::OnInitDialog()
{
     CPropertySheet::OnInitDialog();
     return true;
}
BEGIN_MESSAGE_MAP (CMyPropertySheet, CPropertySheet)
//{{AFX_MSG_MAP (CMyPropertySheet)
// ON_BN_CLICKED(IDC_BLUE_LIKE, OnBlueLike)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

///////////////////////// PROPERTY PAGE 1 2 3 ////////////////////////////////////////////////////
CMyPropertyPage1::CMyPropertyPage1()
     : CPropertyPage (CMyPropertyPage1::IDD)  { }

BOOL CMyPropertyPage1::OnInitDialog()
{
     CPropertyPage::OnInitDialog();
     return true;
}
BEGIN_MESSAGE_MAP (CMyPropertyPage1, CPropertyPage)
//{{AFX_MSG_MAP(CMyPropertyPage1)
// ON_BN_CLICKED(IDC_BLUE_LIKE, OnBlueLike)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

    

EXPORT CLASS – from PUtil.dll

<< PUtil.h >>
#ifdef PUTIL_EXPORTS
      #define PUTIL_DECL_EXPIMP _declspec(dllexport)
#else
      #define PUTIL_DECL_EXPIMP _declspec(dllimport)
#endif

<< MyClassA.h >>
#include "PUtil.h" // need to EXPORT
namespace PUtil
{
   class PUTIL_DECL_EXPIMP CMyClassA
   {
   public:
      CMyClassA();
   };
}

<< MyClassA.cpp >>
#include "MyClassA.h"
using namespace std;
using namespace System;
using namespace System::Windows::Forms;

namespace
PUtil
{
   CMyClassA::CMyClassA()
   {
     ---
   }
}

<< VC++  Solution >>
Must define “PUTIL_EXPORTS” in Project Properties of PUtil Project :

VC++ à Configuration Properties à C/C++ à Preprocessor à Preprocessor definition :
Type :  PUTIL_EXPORTS 

 

 

Link Error - LNK2020 Unresolved token declspec(dllimport)

Linking...
Creating library C:\xxx\...\AAA.exp

FileA.obj:error LNK2020: unresolved token (0A000D39)"__declspec(dllimport) const DLG::CFile::vftable""(___imp_??

C:\xxx\  AAA.dll : fatal error LNK1120: 2 unresolved externals

SOLUTION

Must define "MY_EXPORTS" in Project Properties of AAA project, as follows.

VC++ > Configuration Properties > C/C++ > Preprocessor > Preprocessor definition:
Type "AAA_EXPORTS"


C "static" & "extern"

<<  FileA.cpp >>

extern int A ()  // "extern" means visible and usable within the scope of the same binary space (within this dll)
{     }

static int B ()   // "static" means visible and usable within this object scope (within this cpp object)
{     }

If we are to convert this to C++ class, it would be:

class EXPORT CFileA
{
public:
      int A ();       

private:
      int B ();     
}

 

How to Create a New Project Out Of an Old One

From VC++ Solution, remove Project "MyProj".
Windows Explorer : Rename old folder MyOld to MyProjSAVE.
VC++ Solution : Add New Project “MyProj” under the same directory “xxx/xxx”
Make sure to use an appropriate DLL type...
Windows Explorer : Copy all h/cpp from MyProjSAVE to MyProj.
Do not forget aaaaa.h/cpp & bbbbb.h/cpp (even if these belong to a different project.
VC++ Solution/Project : Add existing items to Project MyProj.
Set Project Dependency for this new MyProj as the same as it was for the old MyProj.
Set Properties of this Project as follows: :::

General Character Set Use Multi-Byte Character Set
General Common Language Runtime Support : No Common Language Runtime support
C++ General Additional Include Directories
C++ Advanced Force Include
C++ Precompiled Headers
C++ Preprocessor Preprocessor Definitions
Linker Input Module Definition File : MyProj.def
Linker Input Additional Dependencies … copy from somewhere
Linker Input Ignore Specific Library : NoLongerNeeded.lib
Linker General Additional Library Directories

Also, we must create Debug-Purify / Win32 – Configuration Manager.!!!!!

 

TO DO Items..... 2012-4-2

1.   Facebook

11. Export class --- EXPORT  dllexport / dllimport

22. Export function ---  pt, .def, #if , extern

1.   WPF - Save / Print

1.   lambda / concurrency / mutex / singlrton / c++11

1.   array -- use vector (list is special)

1.   Fix exit error

1.   Use Nurbs for Revolve / Extrude

1.   VS2008 VC++ x64

1.   Animation / SleepEx

1.   WPF - use a cone for xyz axes

1.   View Rotate 2D --- use icon / show a large cross in screen (unclick after mouse-up)

1.   Coord: R / C / S --- Put a large ICON


 

 

 

 

 

 

 

     
                               

 www.iNET1000.com