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 productivity-boosting 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++.
(Click on cover image on the left to download the eBook in CHM / Compiled HTML file format)
Book Chapters:
Windows, Visual C++, and Application Framework Fundamentals
The MFC Library View Class
The Document-View Architecture
Active X: COM, Automation, OLE
Database Management
Programming for the Internet
Copyright© 1998 by David J. Kruglinski
C++ Builder 6 eBook
Developer's Guide (PDF)
Object Pascal Guide (PDF)
Quick Start (PDF)
Documents are in Adobe PDF (Portable Document Format). You'll need a PDF reader to view those documents. C++ 101 recommends FoxIt PDF Reader as it's packed with ton of features, small in size, and best of all... it's totally FREE!
Object Pascal Guide (PDF)
Quick Start (PDF)
Documents are in Adobe PDF (Portable Document Format). You'll need a PDF reader to view those documents. C++ 101 recommends FoxIt PDF Reader as it's packed with ton of features, small in size, and best of all... it's totally FREE!
Differences between C and C++
C++ was based on C and retains a great deal of the functionality. C++ does not retain complete source-level compatability with C. There are a few gotchas for C++ programmers trying to write C code, and C programmers trying to compile with a C++ compiler.
The explanation from Bjarne Stroustrup himself is that this isn't type safe. What this means is that you can have a void* that points to anything at all, and if you then assign the address stored in that void* to another pointer of a different type, there isn't any warning at all about it.
Consider the following:
Implicit Assignment from void*
You cannot implicitly assign from a void* to any other type. For instance, the following is perfectly valid in C (in fact, it's arguably the preferable way of doing it in C)int *x = malloc(sizeof(int) * 10);but it won't compile in C++. (Try it yourself!)
The explanation from Bjarne Stroustrup himself is that this isn't type safe. What this means is that you can have a void* that points to anything at all, and if you then assign the address stored in that void* to another pointer of a different type, there isn't any warning at all about it.
Consider the following:
int an_int;When you assign *double_ptr the value 5, it's writing 8 bytes of memory, but the integer variable an_int is only 4 bytes. Forcing a cast from a void pointer makes the programmer pay attention to these things.
void *void_pointer = &an_int;
double *double_ptr = void_pointer;
*double_ptr = 5;
Freeing arrays: new[] and delete[]
In C, there's only one major memory allocation function: malloc. You use it to allocate both single elements and arrays:int *x = malloc( sizeof(int) );and you always release the memory in the same way:
int *x_array = malloc( sizeof(int) * 10 );
free( x );In C++, however, memory allocation for arrays is somewhat different than for single objects; you use the new[] operator, and you must match calls to new[] with calls to delete[] (rather than to delete).
free( x_array );
int *x = new int;The short explanation is that when you have arrays of objects, delete[] with properly call the destructor for each element of the array, whereas delete will not.
int *x_array = new int[10];
delete x;
delete[] x;
You must declare functions before use
Although most good C code will follow this convention, in C++ it is strictly enforced that all functions must be declared before they are used. This code is valid C, but it is not valid C++:#include
int main()
{
foo();
return 0;
}
int foo()
{
printf( "Hello world" );
}
Gotcha for a C++ programmer using C
Structs and Enums
You have to include the struct keyword before the name of the struct type to declare a struct: In C++, you could do thisstruct a_structand have a new instance of a_struct called struct_instance. In C, however, we have to include the struct keyword when declaring struct_instance:
{
int x;
};
a_struct struct_instance;
struct a_struct struct_instance;In fact, a similar situation also holds for declaring enums: in C, you must include the keyword enum; in C++, you don't have to. As a side note, most C programmers get around this issue by using typedefs:
typedef struct struct_nameNow you can declare a struct with
{
/* variables */
} struct_name_t;
struct_name_t struct_name_t_instance;But there is another gotcha for C++ programmers: you must still use the "struct struct_name" syntax to declare a struct member that is a a pointer to the struct.
typedef struct struct_name
{
struct struct_name instance;
struct_name_t instance2; /* invalid! The typedef isn't defined yet */
} struct_name_t;
C++ has a much larger library
C++ has a much larger library than C, and some things may be automatically linked in by C++ when they are not with C. For instance, if you're used to using g++ for math-heavy computations, then it may come as a shock that when you are using gcc to compile C, you need to explicitly include the math library for things like sin or even sqrt:% g++ foo.cc
or
% gcc foo.c -lm
No Boolean Type
C does not provide a native boolean type. You can simulate it using an enum, though:typedef enum {FALSE, TRUE} bool;
main Doesn't Provide return 0 Automatically
In C++, you are free to leave off the statement 'return 0;' at the end of main; it will be provided automatically:int main()but in C, you must manually add it:
{
printf( "Hello, World" );
}
int main()
{
printf( "Hello, World" );
return 0;
}
Configuring Borland C++ 5.5
Before proceeding to this step to configure Borland C++ 5.5, refer to BCC5 installation guide, after it's done, follow these steps...
Before you can use the compiler you need to configure the tools for your machine. This process requires you to tell the operating system (Windows) where the executable files are, and to tell the compiler where the include and library files are located. You'll also need to tell the compiler if you want to pass any special switches.
To configure the tools we'll write one batch (
We'll start by writing batch file to configure the environment:
Before you can use the compiler you need to configure the tools for your machine. This process requires you to tell the operating system (Windows) where the executable files are, and to tell the compiler where the include and library files are located. You'll also need to tell the compiler if you want to pass any special switches.
To configure the tools we'll write one batch (
BAT
) file and two CFG
files. This assumes you are using Windows 95/98. If you are using NT, W2K, or XP, you can write a CMD file instead of a BAT file, but a BAT file will work as well.We'll start by writing batch file to configure the environment:
- Use any plain text editor to write the batch file. You could use Notepad to accomplish this task.
- Before you make any changes, save the empty file as
StartBC.bat
in theC:\BCC55
directory. If you are running Windows NT or W2K, save the file asStartBC.cmd
instead. Be sure you put quotes around the file name when you save it, oterwise Notepad will save your file asStartBC.bat.txt
. - Add the following two lines to your batch file, and then save it again.
PATH=C:\BCC55\BIN;%PATH%
DOSKEY /INSERT
bcc32.dll
:- Use any plain text editor (such Notepad) to edit the config file.
- Before you make any changes, save the empty file as bcc32.cfg in the C:\BCC55\BIN directory. Note that this is not the same directory where you saved StartBC.bat.
Note: Be sure you put quotes around the file name when you save it, or else Notepad will save your file as bcc32.cfg.txt, which won't work at all. - Add the following lines to your file, and then save it again. Note, however, that if you've installed the compiler in a directory other than
C:\BC55\BIN
, you'll need to adjust the lines so that they reflect the actual location of the compiler's include and library files.-I "C:\BCC55\INCLUDE"
-L "C:\BCC55\LIB;C:\BCC55\LIB\PSDK"
-P
-v-
-w
-DWINVER=0x0400
-D_WIN32_WINNT=0x0400
For your information, each of these lines means:
-I : tells the compiler where to look for system include files
-L : tells the compiler where to look for libraries
-P : tells the compiler to compile using C++, even if the source ends with .c
-v-: tells the compiler to turn off debugging.
-w : tells the compiler to issue warnings
-D : defines several constants so your executables will work with W95/98/NT
Note that the I, L, P, and D are uppercase, while the v and w are lowercase. This is important, because if you use an uppercase W, you generate a Windows application instead of warnings.
ilink32.cfg
:- Use any plain text editor (such Notepad) to edit the config file.
- Before you make any changes, save the empty file as ilink32.cfg in the C:\BCC55\BIN directory. Note that this is not the same directory where you saved StartBC.bat.
Note: Be sure you put quotes around the file name when you save it, or else Notepad will save your file as ilink32.cfg.txt, which won't work at all. - Add the following lines to your file, and then save it again. Note, however, that if you've installed the compiler in a directory other than
C:\BC55\BIN
, you'll need to adjust the lines so that they reflect the actual location of the compiler's include and library files.-v-
-x
-L "C:\BCC55\LIB;C:\BCC55\LIB\PSDK"
For your information, each of these lines means:
-L : tells the linker where to look for libraries
-v-: tells the linker to turn off debugging.
-x : tells the linker not to generate a map file
Note that the L are uppercase, while the v and x are lowercase.
Installing Borland C++ Compiler
Once you have downloaded the compiler, you will need to install and configure it. follow these step by step guide to easily installing Borland C++ Compiler v5.5.1 (BCC 5.5 is available for free download from Borland site).
The procedures that follow assume that you will install the command-line tools in a directory named
The procedures that follow assume that you will install the command-line tools in a directory named
C:\BCC55
. If you want to install somewhere else, simply change the path when following these instructions.- Use Windows Explorer to find the file you just downloaded. This is a self-extracting file, so you won't need Zip utility such WinZip to install the tools.
Simply execute the installation program by double-clicking the file from Windows Explorer. - Double-click the file
FreeCommandLineTools.exe
. This will launch the InstallShield installation program. When the first screen pops up, just click Next...
The next screen is the license screen. Read through the license and then click "I Agree".
The next screen asks you to enter the name for the Installation Folder. There's nothing really wrong with the default (C:\Borland\BCC55
), but I've shortened it to C:\BCC55 as previously mentioned. - Unless you are reinstalling, the folder you specified will not exist. Answer Yes when asked if you want to create it. Once you click OK, the installation program will uncompress each of the files and place them in the directory you specified. As it works, it will keep you updated with a progress dialog like snapshot image to the right.
- Once it has uncompressed all of the files, the installer will inform you that "The package has been delivered successfully". Click OK to finish installation.
Subscribe to:
Posts (Atom)