SAMPLE: DLLFloat.exe Converts Floating-Point Numbers to Strings

ID: Q75537

The information in this article applies to:

SUMMARY

DLLFloat.exe is a sample file that contains a DLL- compatible function to convert a floating-point number to a character string. 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.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ DLLFloat.exe (size: 50225 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

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 query words: Keywords : kbfile kbsample kb16bitonly kbDLL kbKernBase

Last Reviewed: December 11, 1998