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 INFORMATION
One 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:
The following is the exported name result:
Note 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:
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:
REFERENCES
Vb4dll.txt included with Visual Basic.
Additional query words: kbNoKeyword Export Dll Function C++ C
Keywords : kbVBp400 kbGrpVB |
Last Reviewed: January 5, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |