This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Copyright© 1998 by David J Kruglinski This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright (c) 1998 by David J Kruglinski All rights reserved No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher Library of Congress Cataloging-in-Publication Data Kruglinski, David Programming Microsoft Visual C++ / David J Kruglinski, Scot Wingo, George Shepherd 5th ed p cm Rev ed of: Inside Visual C++ Includes index ISBN 1-57231-857-0 C++ (Computer program language) Microsoft Visual C++ I Wingo, Scot David II Shepherd, George, 1962- Inside Visual C++ III Kruglinski, IV Title QA76.73.C153K78 1998 005.13'3 dc21 98-27329 CIP Printed and bound in the United States of America WCWC Distributed in Canada by Penguin Books Canada Limited A CIP catalogue record for this book is available from the British Library Microsoft Press books are available through booksellers and distributors worldwide For further information about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329 Visit our Web site at mspress.microsoft.com Macintosh and TrueType fonts are registered trademarks of Apple Computer, Inc Intel is a registered trademark of Intel Corporation ActiveX, FoxPro, FrontPage, Microsoft, Microsoft Press, MS, MS-DOS, Outlook, PowerPoint, SourceSafe, Visual Basic, Visual C++, Visual J++, Win32, Win64, Windows, and Windows NT are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries Other product and company names mentioned herein may be the trademarks of their respective owners Acquisitions Editor: Eric Stroo Project Editor: Rebecca McKay Technical Editor: Jean Ross This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Acknowledgments I first met David Kruglinski at a software development conference I had just quit my job and started a new company, and I approached David at an author signing for an earlier edition of this book Our new company was going to focus on Microsoft Foundation Class (MFC)/Microsoft Visual C++ class libraries I hoped that David would listen to our ideas and maybe provide some feedback on our products and their usefulness to the Visual C++ development community—a community that he had both helped to build and understood like the back of his own hand Much to my surprise, David was very excited about the product ideas and asked if I could send him evaluation copies of our products I did, and we started a long e-mail conversation about our products and ideas for improvements David gave his time, expertise, and great opinions freely, without ever asking for any compensation—he genuinely wanted to help us make products for the Visual C++ developer that would make MFC/Visual C++ better I first heard about David's fatal paragliding accident via a posting on a newsgroup and initially thought it was some kind of cruel hoax I called David's agent, who checked into the story, and much to my shock it was true With David's passing, the Visual C++ community has lost one of its brightest and most giving stars Talk to any Visual C++ developers about how they first learned Visual C++ and invariably they will say, "the Kruglinski book!" The Visual C++ community owes David greatly for what he gave us and taught us about Visual C++ over the years It goes without saying that he should receive special acknowledgment for this book, and our thoughts go out to his family and friends for their loss It is a great honor to carry on the Kruglinski tradition with this fifth edition of Inside Visual C++ (now called Programming Microsoft Visual C++, Fifth Edition) We have done our best to stay true to David's vision of this book, following his format and style as closely as possible Thanks to my wife Kris and to my son, Sean, for putting up with all of the late nights and weekends of writing Many thanks also go to my coauthor, George Shepherd, who always helps me get motivated for a late night of book writing with his upbeat, wacky, and great personality Thanks to Claire Horne, our agent, for helping us get on board with the project Visual C++, and therefore this book, wouldn't exist if not for the many members of the Visual C++ team Special thanks to Mike Blaszczak, Walter Sullivan, Dean McCrory, Rick Laplante, Marie Huwe, Christian Gross, and Jim Springfield for all of the help they have provided over the years Finally, but not least, thanks to the folks at Microsoft Press who worked on this project—especially Kathleen Atkins, Jim Fuchs, Becka McKay, John Pierce, Jean Ross, Eric Stroo, and the entire production team who worked extremely hard to get this large book out and into your hands with the highest quality possible —Scot Wingo Much work goes into writing books—even revisions of existing work I'd like to acknowledge the following people for helping me get this work out the door: First I'd like to thank my wife Sandy for sticking with me while I worked to get the pages and chapters out Sandy has been an invaluable source of encouragement throughout my software endeavors Thanks to my son, Teddy, for being patient with me as I bowed out on various activities every once in a while I wish to thank my mother Betsy for engendering in me a desire to write and my twin brother Patrick for being a great Java foil for me—and for arguing cogently with me about various hardware and software platform issues Thanks to Claire Horne of the Moore Literary Agency for helping to get this project rolling with Microsoft Press To Scot Wingo, thanks for taking on another writing project with me And thanks to the folks at Stingray— you all are a great bunch to work with Thanks to all the folks at DevelopMentor for providing a great training and learning environment And thanks to Don Box for continuing to explain COM in a way that makes sense Getting a book out involves more than just authors I wish to thank everyone at Microsoft Press who helped kick Programming Microsoft Visual C++, Fifth Edition out the door, especially Eric Stroo for his kindness and patience, Kathleen Atkins and Becka McKay for sifting through our text and making it ever more readable, Jean Ross for balancing out the technical review to catch even the most minute error, and John Pierce for keeping everything on track This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com John Pierce for keeping everything on track Finally, thanks to David Kruglinski for starting this project While I never had the opportunity to meet David, his writing had a measuable impact on me when first learning MFC I hope Scot and I did justice to the work you began —George Shepherd This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Introduction The 6.0 release of Visual C++ shows Microsoft's continued focus on Internet technologies and COM, which are key components of the new Windows Distributed interNet Application Architecture (DNA) In addition to supporting these platform initiatives, Visual C++ 6.0 also adds an amazing number of productivityboosting features such as Edit And Continue, IntelliSense, AutoComplete, and code tips These features take Visual C++ to a new level We have tried to make sure that this book keeps you up to speed on the latest technologies being introduced into Visual C++ This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com MFC, ATL, and WFC—Is MFC Dead? Ever since Microsoft released the Active Template Library (ATL) as part of Visual C++, Windows developers have speculated that the Microsoft Foundation Class Library (MFC) was no longer "en vogue" at Microsoft and that future efforts would focus on newer libraries such as ATL Recently, Microsoft released another class library, Windows Foundation Classes (WFC), for Java Windows developers, which has unfortunately helped to fan the rumors that "MFC is dead." The rumors of MFC's demise are definitely premature Visual C++ 6.0 has added significant functionality to MFC and ATL in parallel, which indicates that both libraries will receive equal attention moving forward Part of the problem is that the design goals of each library are sometimes not clearly stated and therefore are not clearly understood by the Visual C++ developer MFC is designed to be a great class library for creating graphically rich, sophisticated Windows applications ATL is designed to make it easy to create extremely lightweight COM objects and ActiveX controls Each of these design goals has resulted in a different library to empower the developer Another common misconception is that MFC and ATL are mutually exclusive This is definitely not the case! In fact, it is very easy to create ATL-based COM objects that use MFC The only issue is that since many developers choose ATL for its lightweight nature, using MFC, which is feature-rich and "heavy," seems to contradict the reason for choosing ATL While this might be the case for some developers, it doesn't make ATL and MFC mutually exclusive While ATL does not replace MFC, we think it is an important part of Visual C++, so in this edition of Programming Microsoft Visual C++ we have added two chapters that cover the ATL class libraries This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com C++ vs Java In the last couple of years, there has been a great deal of interest in the Java programming language Why should you choose C++ over Java? In the first place, a compiled program will always be faster than an interpreted program Think about a high-performance spreadsheet program with cell formulas and macros Now imagine the Java virtual machine interpreting the code that, in turn, interprets the formulas and macros Not pretty, is it? With just-in-time compilation, it's necessary to compile the program every time you load it Will that code be as good as the optimized output from a C++ compiler? Execution speed is one factor; access to the operating system is another For security reasons, Java applets can't perform such tasks as writing to disk and accessing serial ports In order to be platformindependent, Java application programs are limited to the "lowest common denominator" of operating system features A C++ program for Microsoft Windows is more flexible because it can call any Win32 function at any time Java will be an important language, but we believe it's just another language, not a revolution If you need an Internet applet or a truly platform-independent application, choose Java If you need efficiency and flexibility, choose C++ This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Who Can Use This Book The product name "Visual C++" misleads some people They think they've bought a pure visual programming system similar to Microsoft Visual Basic, and for the first few days the illusion persists However, people soon learn that they must actually read and write C++ code The Visual C++ wizards save time and improve accuracy, but programmers must understand the code that the wizards generate and, ultimately, the structure of the MFC library and the inner workings of the Windows operating system Visual C++, with its sophisticated application framework, is for professional programmers, and so is this book We assume that you're proficient in the C language—you can write an if statement without consulting the manual And we assume that you've been exposed to the C++ language—you've at least taken a course or read a book, but maybe you haven't written much code Compare learning C++ to learning the French language You can study French in school, but you won't be able to speak fluently unless you go to France and start talking to people Reading this book is like taking your trip to France! We won't assume, however, that you already know Windows programming We're sure that proficient C programmers can learn Windows the MFC way It's more important to know C++ than it is to know the Win32 application programming interface (API) You should, however, know how to run Windows and Windows-based applications What if you're already experienced with the Win32 API or with the MFC library? There's something in this book for you too First you'll get some help making the transition to Win32 programming Then you'll learn about new features such as Data Access Objects (DAO), ActiveX control container support, and the controls introduced with Windows 95 If you haven't already figured out the Component Object Model (COM), this book presents some important theory that will get you started on understanding ActiveX Controls You'll also learn about the ATL class library, the new Microsoft Internet Explorer 4.0 common controls, and OLE/DB database programming Finally, you'll learn C++ programming for the Internet (including the hot new topic Dynamic HTML) We've even included coverage on how to make your Visual C++ programs work on the new Windows CE operating system This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com What's Not Covered It's not possible to cover every aspect of Windows-based programming in a single book We exclude topics that depend on special-purpose hardware and software, such as MAPI, TAPI, and communications port access We cover using ActiveX controls in an application, but we'll defer the subject of writing ActiveX controls to Adam Denning and his ActiveX Controls Inside Out (Microsoft Press, 1997) We get you started with 32-bit memory management, DLL theory, and multithreaded programming techniques, but you need to get the third edition of Jeffrey Richter's Advanced Windows (Microsoft Press, 1997) if you're serious about these subjects Another useful book is MFC Internals by George Shepherd and Scot Wingo (AddisonWesley, 1996) This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com How to Use This Book When you're starting with Visual C++, you can use this book as a tutorial by going through it sequentially Later you can use it as a reference by looking up topics in the table of contents or in the index Because of the tight interrelationships among many application framework elements, it wasn't possible to cleanly isolate each concept in its own chapter, so the book really isn't an encyclopedia When you use this book, you'll definitely want to keep the online help available for looking up classes and member functions If you're experienced with the Win16 version of Visual C++, scan Part I for an overview of new features Then skip the first three chapters of Part II, but read Chapters through 12, which cover elements specific to Win32 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Introduction The 6.0 release of Visual C++ shows Microsoft's continued focus on Internet technologies and COM, which are key components of the new Windows Distributed interNet Application Architecture (DNA) In addition to supporting these platform initiatives, Visual C++ 6.0 also adds an amazing number of productivityboosting features such as Edit And Continue, IntelliSense, AutoComplete, and code tips These features take Visual C++ to a new level We have tried to make sure that this book keeps you up to speed on the latest technologies being introduced into Visual C++ This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com MFC, ATL, and WFC—Is MFC Dead? Ever since Microsoft released the Active Template Library (ATL) as part of Visual C++, Windows developers have speculated that the Microsoft Foundation Class Library (MFC) was no longer "en vogue" at Microsoft and that future efforts would focus on newer libraries such as ATL Recently, Microsoft released another class library, Windows Foundation Classes (WFC), for Java Windows developers, which has unfortunately helped to fan the rumors that "MFC is dead." The rumors of MFC's demise are definitely premature Visual C++ 6.0 has added significant functionality to MFC and ATL in parallel, which indicates that both libraries will receive equal attention moving forward Part of the problem is that the design goals of each library are sometimes not clearly stated and therefore are not clearly understood by the Visual C++ developer MFC is designed to be a great class library for creating graphically rich, sophisticated Windows applications ATL is designed to make it easy to create extremely lightweight COM objects and ActiveX controls Each of these design goals has resulted in a different library to empower the developer Another common misconception is that MFC and ATL are mutually exclusive This is definitely not the case! In fact, it is very easy to create ATL-based COM objects that use MFC The only issue is that since many developers choose ATL for its lightweight nature, using MFC, which is feature-rich and "heavy," seems to contradict the reason for choosing ATL While this might be the case for some developers, it doesn't make ATL and MFC mutually exclusive While ATL does not replace MFC, we think it is an important part of Visual C++, so in this edition of Programming Microsoft Visual C++ we have added two chapters that cover the ATL class libraries This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com C++ vs Java In the last couple of years, there has been a great deal of interest in the Java programming language Why should you choose C++ over Java? In the first place, a compiled program will always be faster than an interpreted program Think about a high-performance spreadsheet program with cell formulas and macros Now imagine the Java virtual machine interpreting the code that, in turn, interprets the formulas and macros Not pretty, is it? With just-in-time compilation, it's necessary to compile the program every time you load it Will that code be as good as the optimized output from a C++ compiler? Execution speed is one factor; access to the operating system is another For security reasons, Java applets can't perform such tasks as writing to disk and accessing serial ports In order to be platformindependent, Java application programs are limited to the "lowest common denominator" of operating system features A C++ program for Microsoft Windows is more flexible because it can call any Win32 function at any time Java will be an important language, but we believe it's just another language, not a revolution If you need an Internet applet or a truly platform-independent application, choose Java If you need efficiency and flexibility, choose C++ This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Who Can Use This Book The product name "Visual C++" misleads some people They think they've bought a pure visual programming system similar to Microsoft Visual Basic, and for the first few days the illusion persists However, people soon learn that they must actually read and write C++ code The Visual C++ wizards save time and improve accuracy, but programmers must understand the code that the wizards generate and, ultimately, the structure of the MFC library and the inner workings of the Windows operating system Visual C++, with its sophisticated application framework, is for professional programmers, and so is this book We assume that you're proficient in the C language—you can write an if statement without consulting the manual And we assume that you've been exposed to the C++ language—you've at least taken a course or read a book, but maybe you haven't written much code Compare learning C++ to learning the French language You can study French in school, but you won't be able to speak fluently unless you go to France and start talking to people Reading this book is like taking your trip to France! We won't assume, however, that you already know Windows programming We're sure that proficient C programmers can learn Windows the MFC way It's more important to know C++ than it is to know the Win32 application programming interface (API) You should, however, know how to run Windows and Windows-based applications What if you're already experienced with the Win32 API or with the MFC library? There's something in this book for you too First you'll get some help making the transition to Win32 programming Then you'll learn about new features such as Data Access Objects (DAO), ActiveX control container support, and the controls introduced with Windows 95 If you haven't already figured out the Component Object Model (COM), this book presents some important theory that will get you started on understanding ActiveX Controls You'll also learn about the ATL class library, the new Microsoft Internet Explorer 4.0 common controls, and OLE/DB database programming Finally, you'll learn C++ programming for the Internet (including the hot new topic Dynamic HTML) We've even included coverage on how to make your Visual C++ programs work on the new Windows CE operating system This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com What's Not Covered It's not possible to cover every aspect of Windows-based programming in a single book We exclude topics that depend on special-purpose hardware and software, such as MAPI, TAPI, and communications port access We cover using ActiveX controls in an application, but we'll defer the subject of writing ActiveX controls to Adam Denning and his ActiveX Controls Inside Out (Microsoft Press, 1997) We get you started with 32-bit memory management, DLL theory, and multithreaded programming techniques, but you need to get the third edition of Jeffrey Richter's Advanced Windows (Microsoft Press, 1997) if you're serious about these subjects Another useful book is MFC Internals by George Shepherd and Scot Wingo (AddisonWesley, 1996) This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com How to Use This Book When you're starting with Visual C++, you can use this book as a tutorial by going through it sequentially Later you can use it as a reference by looking up topics in the table of contents or in the index Because of the tight interrelationships among many application framework elements, it wasn't possible to cleanly isolate each concept in its own chapter, so the book really isn't an encyclopedia When you use this book, you'll definitely want to keep the online help available for looking up classes and member functions If you're experienced with the Win16 version of Visual C++, scan Part I for an overview of new features Then skip the first three chapters of Part II, but read Chapters through 12, which cover elements specific to Win32 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com The Organization of This Book As the table of contents shows, this book has six parts and an appendix section Part I: Windows, Visual C++, and Application Framework Fundamentals In this part, we try to strike a balance between abstract theory and practical application After a quick review of Win32 and the Visual C++ components, you'll be introduced, in a gentle way, to the MFC application framework and the document-view architecture You'll look at a simple "Hello, world!" program, built with the MFC library classes, that requires only 30 lines of code Part II: The MFC Library View Class The MFC library documentation presents all the application framework elements in quick succession, with the assumption that you know the original Windows API In Part II, you're confined to one major application framework component—the view, which is really a window You'll learn here what experienced Windows programmers know already, but in the context of C++ and the MFC library classes You'll use the Visual C++ tools that eliminate much of the coding drudgery that early Windows programmers had to endure Part II covers a lot of territory, including graphics programming with bitmaps, dialog data exchange, ActiveX control usage, 32-bit memory management, and multithreaded programming The exercises will help you to write reasonably sophisticated Windows-based programs, but those programs won't take advantage of the advanced application framework features Part III: The Document-View Architecture This part introduces the real core of application framework programming—the document-view architecture You'll learn what a document is (something much more general than a word processing document), and you'll see how to connect the document to the view that you studied in Part II You'll be amazed, once you have written a document class, at how the MFC library simplifies file I/O and printing Along the way, you'll learn about command message processing, toolbars and status bars, splitter frames, and context-sensitive help You'll also be introduced to the Multiple Document Interface (MDI), the current standard for Windows-based applications Part III also contains a discussion of dynamic link libraries (DLLs) written with the MFC library You'll learn the distinction between an extension DLL and a regular DLL If you're used to Win16 DLLs, you'll notice some changes in the move to Win32 Part IV: ActiveX: COM, Automation, and OLE COM by itself deserves more than one book Part IV will get you started in learning fundamental COM theory from the MFC point of view You'll progress to Automation, which is the link between C++ and Visual Basic for Applications (VBA) You'll also become familiar with uniform data transfer and structured storage, and you'll learn the basics of compound documents and embedded objects Part V: Database Management Windows-based programs often need access to information in large databases Visual C++ now supports two separate database management options: Open Database Connectivity (ODBC) and Data Access Objects (DAO) Part V offers a chapter on each option You'll learn about the extensive MFC and wizard support for both options, and you'll see the differences between and similarities of ODBC and DAO We'll also cover a new data access technology, OLE/DB, which is supported by ATL OLE/DB consumer and providers Part VI: Programming for the Internet This part starts with a technical Internet tutorial that covers the TCP/IP protocol plus the Winsock and WinInet APIs You'll learn how to write C++ server and client programs for the Internet and the intranet, you'll learn how to write ISAPI DLLs that extend the Microsoft Internet Information Server, and you'll learn how to program for Dynamic HTML We've also included coverage on Windows CE in this section Appendixes Appendix A contains a list of message map macros and their corresponding handler function prototypes ClassWizard usually generates this code for you, but sometimes you must make manual entries This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com ClassWizard usually generates this code for you, but sometimes you must make manual entries Appendix B offers a description of the MFC application framework's runtime class information and dynamic creation system This is independent of the RTTI (runtime type information) feature that is now a part of ANSI C++ This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Win32 vs Win16 Lots of old computers out there are still running Windows 3.1 However, there's not much point in spending money writing new programs for obsolete technology This edition of Programming Microsoft Visual C++ is about 32-bit programming for Microsoft Windows 95, Microsoft Windows 98, and Microsoft Windows NT using the Win32 API If you really need to 16-bit programming, find an old copy of the second edition of this book This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Windows 95 and Windows 98 vs Windows NT Visual C++ version 6.0 requires either Windows 95, Windows 98, or Windows NT version 4.0 or later, all of which have the same user interface We recommend that you use Windows NT as your development platform because of its stability—you can often go for months without rebooting your computer If you use only the MFC programming interface, your compiled programs will run under Windows 95, Windows 98, and Windows NT, but a program can include Win32 calls that use specific Windows 98 or Windows NT features This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Going Further with Windows: The "For Win32 Programmers" Sidebars This book can't offer the kind of detail, tricks, and hidden features found in the newer, specialized books on Win32 Most of those books are written from the point of view of a C-language programmer: in order to use them, you'll have to understand the underlying Win32 API and its relationship to the MFC library In addition, you'll need to know about the Windows message dispatch mechanism and the role of window classes This book's "For Win32 Programmers" sidebars, scattered throughout the text, help you make the connection to low-level programming for Windows These specially formatted boxes help experienced C programmers relate new MFC library concepts to principles they're already familiar with If you're unfamiliar with low-level programming, you should skip these notes the first time through, but you should read them on your second pass through the book Even though you may never write a low-level Windowsbased program with a WinMain function, for example, you eventually need to know how the Windows operating system interacts with your program This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Using the Companion CD-ROM The companion CD-ROM bound inside the back cover of this book contains the source code files for all the sample programs The executable program files are included, so you won't have to build the samples that you're interested in To install the companion CD-ROM's files, insert the disc in your CD-ROM drive and run the Setup program Follow the on-screen instructions The Setup program copies about 30 MB of files to your hard disk If you prefer, you can manually install only the files for individual projects Simply tree-copy the corresponding subdirectories from the CD-ROM to c:\vcpp32 Because each project is self-contained, no additional files from other projects are needed (You'll need to remove the read-only attribute from these files if you copy them using Windows Explorer or File Manager.) Many of the files on the companion CD-ROM have long filenames If you use Windows 95 and your CD-ROM drive uses a real-mode driver, you'll see truncated names for these files and you might not see all of the files or directories The Setup program will still work correctly, however, by copying files from a special \SETUP directory on the CD-ROM and renaming them with their proper long filenames You can then browse the files on your hard disk Alternatively, you can browse the files using the 8.3 aliases in the \SETUP directory on the CD-ROM With a conventional C-language program using the Windows API, the source code files tell the whole story With the MFC library application framework, things are not so simple AppWizard generates much of the C++ code, and the resources originate in the resource editors The examples in the early chapters of this book include step-by-step instructions for using the tools to generate and customize the source code files You'd be well advised to walk through those instructions for the first few examples; there's very little code to type For the middle chapters, use the code from the companion CD-ROM but read through the steps in order to appreciate the role of the resource editors and the wizards For the final chapters, not all the source code is listed You'll need to examine the companion CD-ROM's files for those examples For Win32 Programmers: Unicode Until recently, Windows-based programs have used only the ANSI character set, which consists of 256 single-byte characters Developers targeting the Asian software market are moving to the Unicode character set, which consists of 65,536 characters, each bytes (wide) A third option, the double-byte character set (DBCS), includes both 1byte characters and 2-byte characters, but DBCS is falling out of favor The MFC library and the runtime library both support Unicode applications If you define the constant _UNICODE and follow the steps described in the online documentation, all your character variables and constant strings will be wide and the compiler will generate calls to the wide-character versions of the Win32 functions This assumes that you use certain macros when you declare character pointers and arrays—for example, TCHAR and _T You'll hit a snag, though, if you try to run your MFC Unicode applications under Windows 95 or Windows 98, because they don't support Unicode internally Even though Windows 95 and Windows 98 have wide-character versions of Win32 functions, those functions return a failure code Windows NT, on the other hand, uses Unicode internally and has two versions of the Win32 functions that deal with characters If you call a single-byte version, Windows NT makes the necessary conversions to and from wide characters This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com wide characters None of the sample programs in this book are configured for Unicode All the programs use single-byte types such as char and single-byte string constants, and they not define _UNICODE If you run the samples under Windows NT, the operating system will the necessary single-to-wide conversions; if you run them under Windows 95 or Windows 98, the interface is pure single-byte One area in which you're forced to deal with wide characters is COM All non-MFC COM functions (except DAO functions) that have string and character parameters require wide (OLECHAR) characters If you write a non-Unicode program, you must the conversions yourself with the help of the MFC CString class and various MFC macros If you want to write Unicode applications, read the Unicode chapter in Jeffrey Richter's Advanced Windows You should also read the Unicode material in the Visual C++ online documentation This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Technical Notes and Sample Programs The MSDN Library for Visual Studio 6.0 contains technical notes and sample programs that are referenced in this book The technical notes, identified by number, are available from the Contents tab under the heading: MSDN Library Visual Studio 6.0 Visual C++ Documentation Reference Microsoft Foundation Class Library and Templates Microsoft Foundation Class Library MFC Technical Notes The MSDN CD-ROM also contains a number of MFC sample programs also referenced in the book and identified by name These sample programs are documented under the heading: MSDN Library Visual Studio 6.0 Visual C++ Documentation Samples MFC Samples This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Support Every effort has been made to ensure the accuracy of this book and the contents of the companion disc Microsoft Press provides corrections for books through the Web at: http://mspress.microsoft.com/mspress/support/ If you have comments, questions, or ideas regarding this book or the companion disc, please send them to Microsoft Press using postal mail or e-mail: Microsoft Press Attn: Programming Microsoft Visual C++ Editor One Microsoft Way Redmond, WA 98052-6399 MSPINPUT@MICROSOFT.COM Please note that product support is not offered through the above mail addresses For support information regarding Microsoft Visual C++, you can call the technical support line at (425) 635-7007 weekdays between a.m and p.m Pacific time Microsoft also provides information about Visual C++ at http://www.microsoft.com/visualc/ and about the Microsoft Developer Network at http://www.microsoft.com/MSDN/ ... edition of Programming Microsoft Visual C++ is about 32-bit programming for Microsoft Windows 95, Microsoft Windows 98, and Microsoft Windows NT using the Win32 API If you really need to 16-bit programming, ... please send them to Microsoft Press using postal mail or e-mail: Microsoft Press Attn: Programming Microsoft Visual C++ Editor One Microsoft Way Redmond, WA 98052-6399 MSPINPUT @MICROSOFT. COM Please... Intel Corporation ActiveX, FoxPro, FrontPage, Microsoft, Microsoft Press, MS, MS-DOS, Outlook, PowerPoint, SourceSafe, Visual Basic, Visual C++, Visual J++, Win32, Win64, Windows, and Windows