Visual Basic Requirements for Exported DLL FunctionsLast reviewed: August 14, 1996Article ID: Q142840 |
The information in this article applies to:
SUMMARYTo use a function from an exported DLL in a Visual Basic program, certain requirements must be met for the function to be successfully used by Visual Basic. Visual Basic expects this exported DLL function to work like a Windows API call. This article summarizes the Visual Basic requirements and some of the requirements if you are creating your own exported DLL.
MORE INFORMATIONOne of the features of Visual Basic is the ability to use a function stored in a DLL. Visual Basic assumes that the exported DLL functions have the same attributes as a Windows API function. In order to use a function from an exported DLL in a Visual Basic program, Visual Basic requires the following:
Requirements for Calling Functions
Notes on Creating Exported DLL in Visual C++This section provides some information for creating an exported DLL that meets the Visual Basic requirements using Microsoft Visual C++. Other C++ compilers may or may not support the keywords used in this section. Visual Basic requires that the function receiving the arguments also maintain the stack. The Visual C++ keyword that can perform the correct stack maintenance is _stdcall. The _stdcall keyword decorates the function name with a preceding underscore and appends '@n' where n is the number of bytes required to contain the function's arguments and the return value. For example, if you create a function called GetWindowSize and use the _stdcall keyword to provide stack maintenance, the function is defined as follows:
int GetWindowSize (int nIndex)The following is the exported name result:
_GetWindowSize@8Note the preceding underscore that is added by the _stdcall keyword. To export the file, you can either use the _declspec(dllexport) keyword or a DEF file EXPORT section. The _declspec(dllexport) keyword exports the function but maintains the name decoration. The following example shows how to implement both the _stdcall and _declspec(dllexport) keyword on a function called DisplayMessage:
_delcspec(dllexport) long _stdcall DisplayMessage (LPSTR szMessage)A DEF file also exports the function name and removes the name decoration. The following example shows how the EXPORT section of a DEF file is implemented for a function called DisplayMessage:
EXPORTS DisplayMessage REFERENCESVb4dll.txt shipping with Visual Basic. "Visual Basic Programmer's Guide," Chapter 26, "Calling Procedures in DLLs."
|
Additional reference words: 4.00 vb4win vb4all Export Dll Function C++ C
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |