SAMPLE: DLLFLOAT Converts Floating-Point Numbers to StringsLast reviewed: February 15, 1996Article ID: Q75537 |
The information in this article applies to:
SUMMARYA 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:
MORE INFORMATIONIn 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:
frexpThe 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |