Prod.: Engine, ver.: 6, ID: 60001174, HowTo : Example of Clearing garbage collector inside VC6

HowTo : Example of Clearing garbage collector inside VC6

Article60001174
TypeHowTo
ProductEngine
Version6
Date Added6/23/2010
Submitted bystavros meimaroglou
Keywords

Subject

Example of Clearing garbage collector inside VC6

Summary

Example of Clearing garbage collector inside VC6

Solution

This article applies for version 6018 and later

NOTE:

The paths of .tlb files must be added depend on your machine.

On your Project->Settings->C++->Preprocessor->Additional Include Directory you must add the debug and release folder where the .tlh files was created.

// testDlg.cpp : implementation file
//


//
//
#import "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.tlb"
#import "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb" rename("ReportEvent","_ReportEvent") rename("value","_value")
#import "C:\Documents and Settings\XPMUser\Desktop\Temp\vdraw6\x86\VectorDraw.Geometry.tlb" rename("value","_value")
#import "C:\Documents and Settings\XPMUser\Desktop\Temp\vdraw6\x86\VectorDraw.Render.tlb" rename("value","_value")
#import "C:\Documents and Settings\XPMUser\Desktop\Temp\vdraw6\x86\VectorDraw.Serialize.tlb"
#import "C:\Documents and Settings\XPMUser\Desktop\Temp\vdraw6\x86\VectorDraw.Professional.tlb" rename("entities","Entities") rename("GetEnvironmentVariable" , "_GetEnvironmentVariable") rename("value","_value")


 


#include "stdafx.h"


 


#include "test.h"
#include "testDlg.h"


#include "vdallp.h"


 


#include "mscorlib.tlh"
#include "System.Drawing.tlh"
#include "VectorDraw.Geometry.tlh"
#include "VectorDraw.Render.tlh"
#include "VectorDraw.Serialize.tlh"
#include "VectorDraw.Professional.tlh"


 


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About


class CAboutDlg : public CDialog
{
public:
 CAboutDlg();


// Dialog Data
 //{{AFX_DATA(CAboutDlg)
 enum { IDD = IDD_ABOUTBOX };
 //}}AFX_DATA


 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CAboutDlg)
 protected:
 virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 //}}AFX_VIRTUAL


// Implementation
protected:
 //{{AFX_MSG(CAboutDlg)
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};


CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
 //{{AFX_DATA_INIT(CAboutDlg)
 //}}AFX_DATA_INIT
}


void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CAboutDlg)
 //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
 //{{AFX_MSG_MAP(CAboutDlg)
  // No message handlers
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog


CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
 : CDialog(CTestDlg::IDD, pParent)
{
 //{{AFX_DATA_INIT(CTestDlg)
  // NOTE: the ClassWizard will add member initialization here
 //}}AFX_DATA_INIT
 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CTestDlg)
 DDX_Control(pDX, IDC_VDWRAPPER1, m_vdraw);
 //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
 //{{AFX_MSG_MAP(CTestDlg)
 ON_WM_SYSCOMMAND()
 ON_WM_PAINT()
 ON_WM_QUERYDRAGICON()
 ON_BN_CLICKED(IDC_TEST, OnTest)
 ON_BN_CLICKED(IDC_CREATEITEMS, OnCreateitems)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers


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


 // Add "About..." menu item to system menu.


 // IDM_ABOUTBOX must be in the system command range.
 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
 ASSERT(IDM_ABOUTBOX < 0xF000);


 CMenu* pSysMenu = GetSystemMenu(FALSE);
 if (pSysMenu != NULL)
 {
  CString strAboutMenu;
  strAboutMenu.LoadString(IDS_ABOUTBOX);
  if (!strAboutMenu.IsEmpty())
  {
   pSysMenu->AppendMenu(MF_SEPARATOR);
   pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  }
 }


 // Set the icon for this dialog.  The framework does this automatically
 //  when the application's main window is not a dialog
 SetIcon(m_hIcon, TRUE);   // Set big icon
 SetIcon(m_hIcon, FALSE);  // Set small icon
 
 // TODO: Add extra initialization here
 
 return TRUE;  // return TRUE  unless you set the focus to a control
}


void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
 {
  CAboutDlg dlgAbout;
  dlgAbout.DoModal();
 }
 else
 {
  CDialog::OnSysCommand(nID, lParam);
 }
}


// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.


void CTestDlg::OnPaint()
{
 if (IsIconic())
 {
  CPaintDC dc(this); // device context for painting


  SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);


  // Center icon in client rectangle
  int cxIcon = GetSystemMetrics(SM_CXICON);
  int cyIcon = GetSystemMetrics(SM_CYICON);
  CRect rect;
  GetClientRect(&rect);
  int x = (rect.Width() - cxIcon + 1) / 2;
  int y = (rect.Height() - cyIcon + 1) / 2;


  // Draw the icon
  dc.DrawIcon(x, y, m_hIcon);
 }
 else
 {
  CDialog::OnPaint();
 }
}


// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTestDlg::OnQueryDragIcon()
{
 return (HCURSOR) m_hIcon;
}


void CTestDlg::OnTest()
{
 // TODO: Add your control notification handler code here
 CWaitCursor wait;
 this->m_vdraw.GetActiveDocument().GetModel().GetEntities().EraseAll();
    m_vdraw.GetActiveDocument().ClearUndoMem();
 VectorDraw_Professional::IvdDocumentPtr docPtr = m_vdraw.GetActiveDocument().GetWrapperObject();
 docPtr->ClearEraseItems();
 docPtr->GarbageCollector();
 docPtr->GarbageCollector();//call twice for complete free of Garbage Collector.
 m_vdraw.Redraw();


}


void CTestDlg::OnCreateitems()
{
 // TODO: Add your control notification handler code here
 CWaitCursor wait;
 for(int i = 0 ; i < 10000; i++)
     this->m_vdraw.GetActiveDocument().GetModel().GetEntities().AddLine(COlePoint(0,i),COlePoint(10000,i));
 this->m_vdraw.GetCommandAction().Zoom(COleVariant("E"),COleVariant(),COleVariant());
}