Using Variable Argument Lists in DLL FunctionsLast reviewed: July 22, 1997Article ID: Q69897 |
3.00 3.10
WINDOWS
kbprg
The information in this article applies to:
SUMMARYUsing variable argument lists in functions in Windows dynamic-link libraries (DLLs) immediately suggests problems because the current data segment is not the same as the current stack segment (DS != SS). However, it is possible to create functions declared with the C calling convention (_cdecl) that can properly access variable argument lists from Windows DLLs using the Windows SDK version 3.0 or later.
MORE INFORMATIONIn the STDARG.H file included with the Windows SDK, macros are defined to manipulate variable argument lists. Because DS != SS in DLLs containing code and data segments, the standard macros will not perform properly in small-model or medium-model DLLs. The standard macros assume that the stack segment (SS) and data segment (DS) are equal for far-data models and use NEAR pointers to access the arguments. However, small-model and medium-model DLLs containing code and data segments use the calling application's SS and the DLL's DS. The standard macros fail to account for this case. If the DLL is a code-only DLL where DS == SS (using the DATA NONE declaration), or if the DLL is large-model, the standard macros will work properly. One way to overcome the problems with the standard macros is to define a new set of macros for use with Windows' DLLs. For example:
/**************************************************************** * * File: wstdarg.h * * Remarks: Macro definitions for variable argument lists * used in DLLs * ****************************************************************/typedef char _far *wva_list ;
#define wva_start( ap, v ) (ap = (wva_list) &v + sizeof( v )) #define wva_arg( ap, t ) (((t _far *)(ap += sizeof( t )))[-1]) #define wva_end( ap ) (ap = NULL) /**************************************************************** * End of File: wstdarg.h ****************************************************************/When these macros are compiled, the stack segment is properly selected to access the arguments. Please note the following caveats concerning the use of variable argument lists in DLLs:
|
Additional reference words: 3.00 3.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |