Exchanging Data Types


The set of Exchange methods that CHttpRequestParams inherits from CValidateObject are designed to access the values inputted by the user and place them in variables in your code. These variables can be of a wide variety of data types. To correctly handle the data conversion required to do this (the user input is always of the type string ); the exchange method is overloaded to handle the most common data types. Consider the following example (notice that some familiar code has been omitted for the sake of brevity):

 bool value;  DWORD result = requestParams->Exchange("organic", &value, NULL); 

This very simple example shows how you can automatically convert the value of an input parameter named organic into a boolean type. All the overloads of Exchange return the same DWORD values you saw for Validate . The only difference is that Exchange won t return VALIDATE_E_LENGTHMIN or VALIDATE_E_LENGTHMAX . Also note that you re passing in NULL as the last parameter; we ll continue to ignore the validation context for now as well.

As you can see, the Exchange method greatly simplifies the task of storing user data into variables in your code. The method has been designed to provide a wide range of support for many common types. Exchange is overloaded for each of the following types:

  • LPCSTR

  • CString

  • GUID

  • bool

One overload of Exchange is a template method. Use this overload to convert to any of the following types:

  • ULONGLONG

  • LONGLONG

  • double

  • int

  • long

  • unsigned long

  • short

  • unsigned short

The conversion routines that ATL Server uses are highly optimized, so you shouldn t worry about any performance degradation when you use them. Also, the set of data types was chosen very carefully so that they would be sufficient for almost every application. Of course, if you do need custom data types, then ATL Server is flexible enough to allow you to use them, and you can find more information about this later in the book.

So far, all the calls that you ve made to Validate and Exchange have passed NULL as the validation context. In the next section you ll look at what the validation context is and how you can use it.




ATL Server. High Performance C++ on. NET
Observing the User Experience: A Practitioners Guide to User Research
ISBN: B006Z372QQ
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net