Groups | Blog | Home
all groups > visual c > may 2005 >

visual c : MC++ basic


Jochen Kalmbach [MVP]
5/28/2005 12:00:00 AM
Hi hangaround!
[quoted text, click to view]

See: push_macro
http://msdn.microsoft.com/library/en-us/vclang/html/vcrefPush_macro.asp

See: pop_macro
http://msdn.microsoft.com/library/en-us/vclang/html/vcrefpop_macro.asp

See: undef
http://msdn.microsoft.com/library/en-us/vclang/html/_predir_the_.23.undef_directive.asp

In short:
It saves the state of the macro "new" and then undefines this macro (so
it will use the C++ new-method).

--
Greetings
Jochen

My blog about Win32 and .NET
hangaround
5/28/2005 9:29:41 AM
What does these codes mean as following?
#pragma push_macro("new")
Carl Daniel [VC++ MVP]
5/28/2005 11:29:12 AM
[quoted text, click to view]

Try reading the documentation. It's online and installed with VC++.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/vcrefpush_macro.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/vcrefpop_macro.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_predir_the_.23.undef_directive.asp

-cd

hangaround
5/28/2005 5:41:01 PM
Now see the code snippet in which that two statements stays
.......
#pragma push_macro("new")
#undef new
CFileDialog dlg(TRUE);
dlg.m_pOFN->lpstrInitialDir = m_strWorkingDir;
dlg.m_pOFN->lpstrTitle = _T("Open an XMLSingle XML File");
dlg.m_pOFN->lpstrFilter = _T("XML Files (*.xml)\0*.xml\0");

if (IDOK == dlg.DoModal())
{
m_lbxAuthors.ResetContent();

XmlTextReader* xmlreader;
try
{
xmlreader = new XmlTextReader(dlg.GetPathName());
.......
since we undef the new , how can we use it in the
xmlreader = new XmlTextReader(dlg.GetPathName());

Carl Daniel [VC++ MVP]
5/28/2005 7:14:51 PM
[quoted text, click to view]

new is a built-in operator in C++, but some libraries (particularly MFC)
define a macro of the same name to "hijack" memory allocation and hook their
own memory tracking system in.

In this case, the #undef is simply to make sure that it's the built-in new
that's being used, not any macro by that name.

-cd

hangaround
5/28/2005 10:35:14 PM
AddThis Social Bookmark Button