SAMPLE: DLLFLOAT Converts Floating-Point Numbers to Strings

Last reviewed: February 15, 1996
Article ID: Q75537
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.1 and 3.0

SUMMARY

A small or medium model dynamic-link library (DLL) cannot use any of the C run-time functions provided with Microsoft C version 6.0 to convert a floating-point number to a character string. However, with Microsoft C/C++ version 7.0 you can use the fcvt() and ecvt() functions. The Windows wsprintf() function does not provide any assistance because wsprintf() does not support floating-point numbers. Therefore, a DLL must be compiled with Microsoft C/C++ version 7.0 or provide its own code to perform the conversion.

DLLFLOAT is a file in the Software Library that contains a DLL- compatible function to convert a floating-point number to a character string.

Download DLLFLOAT.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download DLLFLOAT.EXE (size: 50225 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get DLLFLOAT.EXE (size: 50225 bytes) 
    

MORE INFORMATION

In the Windows environment, an application can use the C run-time functions ecvt, fcvt, gcvt, and sprintf to convert a floating-point number to a character string. However, none of these functions can be used in a DLL because a DLL's data segment is not equal to its stack segment and the design of each function assumes that the two segments are identical.

To work around this assumption, a DLL must contain its own code to perform the conversion. The DLLFLOAT example in the Microsoft Software Library creates a function called ConvertFltToStr to convert a number of the DOUBLE data type to a character string.

Even though ConvertFltToStr is a self-contained function, DLLFLOAT contains a supporting function, MYfrexp, that works around a problem in the small and medium model Microsoft C 6.0 run-time libraries. ConvertFltToStr calls the frexp function to retrieve the mantissa and exponent of the floating-point number. However, there is a problem with the frexp function in the Microsoft C 6.0 small and medium model DLL run-time libraries. For more information on this problem, please query on the following words in the Microsoft Knowledge Base:

   frexp

The ConvertFltToStr and MYfrexp functions can be easily incorporated into a DLL. All required variables and manifest constants are declared inside each function. The DLL must declare a global or static string variable to accept the results of the conversion and must include some standard C run-time header files.

If the floating-point number is of an order of magnitude greater than 10 or less than negative 10, ConvertFltToStr converts the number using scientific notation. Different formatting can be achieved by modifying the code.


Additional reference words: 3.00 3.10 softlib DLLFLOAT.EXE
KBCategory: kbprg kbfile
KBSubcategory: KrDll


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.