October 12, 2002

Create installations with Visual Studio Installer

Introducing Visual StudioInstaller VisualStudio Installer is a free tool from Microsoft for creating installations forWindows applications. Visual Studio Installer is available in two Englishversions: version 1.0 works on Windows 98 and version 1.1 works also on WindowsME and 2000/XP. You can download version 1.1 from here. Before installing Visual Studio

Cleanup Your IF Statements with IN

IF statements can become quite long when you’re testing for multiple values. Using the IN expression can make them more readable.So, instead of typing: IF (@testvar = 1 or @testvar = 7 or @testvar = 8 or @testvar = 55 ) BEGIN..END You can use: if @testvar IN(1, 7, 8,

Use enum Terminated with count

Always use an enum instead of defines and always close the list with an additional count. This makes life simpler and helps the compiler.Instead of defines: #define TypeA 0#define TypeB 1#define TypeC 2#define MAX_TYPES 3// arrayint m_nTypes[MAX_TYPES]// loopfor(int i=0; i

List All the Interfaces Implemented by an Object at Runtime

All you need is a simple class that asks your object for each known interface. Here’s the class QI: #include #include #include class QI : public std::stringstream, protected CRegKey{protected: virtual std::string Query( IUnknown* pUnk ) { if ( pUnk != NULL && ( ERROR_SUCCESS == Open( HKEY_CLASSES_ROOT,”Interface” ) ) )

OpenXML for Multiple Trips to the Database

Suppose you need to make multiple inserts (or updates or deletes) to a SQL Server database?for instance, inserting items in a shopping cart. In the past, you needed to loop through your code and make multiple calls to the database. This can be expensive, especially if you’re talking about hundreds

Fixed-length Strings Using Templates

Instead of writing a string class that contains a (char *), why not write a string class with a fixed char array? Of course, it would be repetitive if you had to declare many classes for each string length (Str16, Str32, etc…), but you can use templates instead: template class

A Simple Way to Make Your Object RTTI & dynamic_cast Compliant

Consider this code: class CA{//…};class CB{//…};CA * CB2CA(CB *pb){ return dynamic_cast(pb);} The CA and CB are totally unrelated classes and the CB2CA function seems to be completely useless. However, what if pb points to some kind of class that can be converted to CA? If you try to compile this

A Sparse Array of Any Type with Fast Access

A sparse array saves memory by not allocating memory for elements that are not initialized or to which you don’t need access. They’re quite easy using the STL map.This example defines a two dimensional array of type SomeData and a three dimensional array of type SomeStruct: #include using std::map;typedefmap arr2SomeData;typedefmap

Output Data into a File

Use the following code: #include void main(){ char name[15]; double salary; ofstream outFile(“FileName.txt”, ios::in); while (outFile){ outFile >> name >> salary; }}

No more posts to show