Creating C++ clients for Whisker

Top  Previous  Next

Creating console-mode C++ applications for Whisker

 

The discussion of SimpleCPPClient covers this. In particular, the text file Building this program – from scratch, in detail.txt gives you step-by-step instructions.

 

Creating Windows-based C++ applications for Whisker

 

In Visual C++, to create the skeleton of a Windows simple application you just follow these steps:

 

1.File New Project MFC AppWizard (exe) give it a name and a directory
2.Choose type (SDI, MDI, dialogue). I'm going to use dialogues for a while because they're easier.
3.Include support for Windows Sockets.
4.Accept all the other defaults.

 

Creating a behavioural task using the library

 

Include the library files in the project

 

Regardless of the type of application you create, you will next want to include the WhiskerClientLib library in your project. Choose Project Add To Project Files, look for files of type Library files (*.lib) and choose either

 

WhiskerClientLib\Debug\WhiskerClientLib_Debug.lib

 

or

WhiskerClientLib\Release\WhiskerClientLib_Release.lib

 

Choose the version of the library that matches your compilation settings; see below.

 

Derive your task's class from CWhiskerTask

 

The core of the behavioural task is a class derived from CWhiskerTask.

 

Insert a new class (Insert New Class) and name it (within the SecondOrder program, it was called CSecondOrderTask). Make it a generic class, and tell the compiler that it's derived from CWhiskerTask with public inheritance.

 

Include the library header file

 

Finally, so your code knows what's in the library, add the following line to your new class's header file:

 

#include "../WhiskerClientLib/WhiskerTask.h"

 

Depending on the directory you are developing your project in, you'll need to edit the path in that statement so that it does actually reach WhiskerTask.h!

 

Debug and Release mode in Visual C++, and the Whisker client library

 

One important thing. Visual C++ applications can be compiled in two modes, Debug and Release. Compiling a project in Debug mode builds information into the resulting program that can be used for debugging; if the application crashes, you can step through the source code to find out where, and so on. Release mode is used for finished products: the resulting file is smaller, but it doesn't contain debug information. You can also let the compiler optimize the code for speed or size when you use Release mode (though I have avoided this since I found some bugs in the VC++ 6.0 optimizer, i.e. it screws the code up sometimes).

 

Given a choice, I would have distributed SimpleCPPClient in Debug mode – after all, it's a programming example and not a useful behavioural task. However, I'm not allowed to distribute the libraries that you need to run Debug mode applications.

 

If you own Visual C++ and want to switch SimpleCPPClient back into Debug mode, open its project by double-clicking on SimpleCPPClient.dsw and choose Build Set Active Configuration. Change the setting to Win32 Debug. When you next build the project (just press F7) it will be in debug mode.

 

I'm afraid there's one other thing to do first. You can't mix debug and release libraries, so I've had to create two versions of the WhiskerClientLib library, which this application uses. Rather than hide it away, I've tried to make it very obvious: if you switch the left-hand view to FileView, you should see WhiskerClientLib_Release.lib in the file list. You should delete this, then choose Project Add To Project Files, look at files of type Library Files (*.lib) and double-click on WhiskerClientLib_Debug.lib, which lives in the WhiskerClientLib\Debug directory.

 

This applies to every application built using WhiskerClientLib; if you want to compile in Debug mode, use the debug version of the library; for release builds, switch to the release library.

 

Warning. If you mix debug and release-mode libraries (i.e. by building your program in debug mode and linking in the release mode of WhiskerClientLib, or vice versa), you will get a few warnings as you build the program. The compiler will let you run the code, but it may CRASH at some unpredictable moment. Don't ignore the warnings! Use the proper library. The errors you get look like this:

 

LINK : warning LNK4098: defaultlib "mfc42.lib" conflicts with use of other libs; use /NODEFAULTLIB:library