HOWTO: Export Functions from a 16-bit DLL |
Q148832
This article describes how to export functions from a 16-bit Dynamic
Link Library (DLL). The topics discussed include:
Q100659 Exporting Callback Functions Not Required in Win32-Based Apps
int FAR Function ();
To declare a pointer as FAR explicity, precede the asterisk with FAR or
__far, as in this example:
int FAR *pInt; Q77986 Using _export Keyword or DEF File EXPORTS StatementTo use __export in the function declaration, precede the function name with the __export keyword, as in this example:
int FAR _export Function ();
If you choose to use the .def file option, you must know the decorated
function name (function names are decorated both in C and C++ by the
compiler). You will find the decorated name in the .map file generated by
the linker. This means that if you don't know the decorated name, you must
first link the DLL without exported functions. Then find the decorated
names in the .map file, construct the EXPORTS section of the .def file, and
link the DLL again. C functions are decorated with a leading underscore.
C++ functions have a more complex decoration.
Q28173 C Run-time Library History and Naming Conventions
// MyDLL.c
#include "windows.h"
// This is a FAR function that returns a FAR pointer to an integer.
// It takes as arguments a FAR pointer to an integer and
// a FAR pointer to a character array.
// Note that this function is exported.
// Note also that because you're compiling with a large memory model,
// all occurrences of FAR may be omitted here.
int FAR * FAR __export DLLfunc1 (int FAR *Marker, LPSTR Message)
{
char Title[200];
wsprintf(Title,"Marker Number %d",*Marker);
MessageBox(NULL,Message,Title,MB_OK);
return Marker;
} Compile with:CL /ALw /GD /c MyDLL.cLink with:LINK /NOD /NOE MyDLL.obj,MyDLL.DLL,,LDLLCEW LIBW,MyDLL.DEFCreate Import Library:IMPLIB MyDLL.LIB MyDLL.DLL
; MyDLL.DEF
LIBRARY MYDLL
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE SINGLE
HEAPSIZE 1024
EXPORTS
WEP PRIVATE
; To implement your own Windows Exit Procedure add the following
; function to your application (referring to it in the .def file isn't
; necessary). The extern "C" is only required if module is C++.
; extern "C" int FAR PASCAL _WEP(int)
; {
; /* Your WEP functionality goes here */
; return 1;
; }
// MyApp.c
#include "windows.h"
// This is a FAR function that returns a FAR pointer to an integer.
// It takes as arguments a FAR pointer to an integer and
// a FAR pointer to a character array.
// Note also that since we are compiling with a medium memory model,
// all occurrences of FAR below are required.
// Note that the NEAR pointers to MainMarker and MainMessage are
// converted to FAR in the function call to DLLfunc1 by the compiler.
int FAR * FAR DLLfunc1 (int FAR *Marker, LPSTR Message);
int FAR PASCAL WinMain (
HINSTANCE hInstCurrent,
HINSTANCE hinstPrevious,
LPSTR lpszCmdLine,
int nCmdShow)
{
int MainMarker = 123;
char *MainMessage = "My WinMain message";
DLLfunc1(&MainMarker,MainMessage);
return 0;
} Compile with:CL /AM /GA /c MyApp.cLink with:LINK /NOD /NOE /STACK:8096 MyApp.obj,MyApp.exe,,LLIBCEW LIBW MyDLL, MyApp.DEF
; MyApp.DEF
NAME MYAPP
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 1024
;STACKSIZE 8096 ;Uncomment this line if /STACK:8096 is not used in
;command line build for LINK. IDE build sets this option
; by default
EXPORTS
; ===List your explicitly exported functions here===
; MyDLL.DEF
LIBRARY MYDLL
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE SINGLE
HEAPSIZE 1024
EXPORTS
_DLLFunc1
WEP PRIVATE
; To implement your own Windows Exit Procedure add the following
; function to your application (referring to it in the .def file is
; not required.) The extern "C" is only required if module is C++.
; extern "C" int FAR PASCAL _WEP(int)
; {
; /* Your WEP functionality goes here */
; return 1;
; }
When building the DLL from the IDE, select "Generate for __far Functions"
in the compiler's "Windows Prolog/Epilog" category.
CL /ALw /GD /GEf /c MyDLL.c
Additional query words: 1.52a 1.52b 1.52c
Keywords : _IK kb16bitonly kbGenInfo kbVC
Issue type : kbhowto
Technology : kbVCsearch kbAudDeveloper kbvc150 kbvc100 kbVC151 kbVC152
|
Last Reviewed: May 9, 2001 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |