15 82 C / C + + Developer Studio M F C C C + + 83 C / C + + M F C D L L D L L 84 M F C MFC DLL M F C 85 MFC DLL 15.1 82 C/C++ C C + + D L L M F C M F C 84 Developer Studio S t u d i o
292 C _ c p l u s p l u s C + + 1. 1) N e w Developer Studio N e w P r o j e c t Win32 Static L i b r a r y O K S t u d i o C C + +. l i b 2) S t u d i o P r o j e c t / S e t t i n g s P r o j e c t / S e t t i n g s S e t t i n g s Win32 Debug L i b r a r y Output File Name d S t d A f x. c p p S t d A f x. h M F C C + + C + M F C 3) C + + P r o j e c t S e t t i n g s C + + C / C + + C a t e g o r y Precompiled header C + + Not using precompiled headers 2. 1). c. c p p 2) C # include <stdlib.h> 3) Windows API # include <windows.h> 4) C C C C + + C + C C + + C e x t e r n c e x t e r n c C _ c p l u s p l u s _ c p l u s p l u C + + T R U E C FA L S E C C + + C + + C /* at the start of your C.h file */ extern "C"
15 293 #endif /* cplusplus */ : : : your C function prototypes : : : /* at the end of your C.h file */ 5) C C + + C 15. 1. 6 C + + 3. Project Settings L i n k. l i b. l i b Object/Library modules M F C C + + M F C C + + M F C ( C C + + ) C C + +. c. c p p C C + + ( c l a s s n e w ) D C /* WzdStatic.h : NonMFC Static Library * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / #if!defined WZDSTAT I C _ H #define WZDSTAT I C _ H extern "C" #endif /* cplusplus */ void WzdMessageBox(LPSTR pszstring); void DestroyWzdWindow(HWND hwnd); void WzdFunc3(BOOL b);
294 / * * WzdStatic.c : NonMFC "C" Static Library Using the Win32 API directly * / #include <stdlib.h> #include <windows.h> #include "WzdStatic.h" BOOL flag=fa L S E ; // must call Win32 API directly void WzdMessageBox(LPSTR pszstring) MessageBox(NULL,pszString,"Wzd Static Library",MB_OK); void DestroyWzdWindow(HWND hwnd) D e s t r o y Wi n d o w ( h W n d ) ; void WzdFunc3(BOOL b) f l a g = b ; C++ // WzdCpp.h : C++ Static Library / / #if!defined WZDCPP_H #define WZDCPP_H class CWzdDllCpp BOOL m_bflag; p u b l i c : C W z d C p p ( ) ; ~ C W z d C p p ( ) ; void WzdMessageBox(LPSTR pszstring); void DestroyWzdWindow(HWND hwnd); void WzdFunc3(BOOL b); ;
15 295 // WzdCpp.cpp : C++ Static library using the Win32 API directly / / #include <windows.h> #include <stdlib.h> #include W z d C p p. h C W z d C p p :: C W z d C p p () m _ b F l a g = FA L S E ; C W z d C p p : : ~ C W z d C p p ( ) // must call the Win32 API directly void CWzdCpp::WzdMessageBox(LPSTR pszstring) MessageBox(NULL,pszString,"Wzd DLL Cpp",MB_OK); void CWzdCpp::DestroyWzdWindow(HWND hwnd) D e s t r o y Wi n d o w ( h W n d ); void CWzdCpp::WzdFunc3(BOOL b) m _ b F l a g = b ; 15.2 83 C/C++ C C + + M F C M F C M F C 84 Developer Studio S t u d i o C _ c p l u s p l u s C + +
296 1. 1) N e w Developer Studio N e w P r o j e c t Wi n 32 Dynamic-Linked Library O K S t u d i o. l i b. d l l. l i b. d l l 2) S t u d i o P r o j e c t / S e t t i n g s P r o j e c t S e t t i n g s S e t t i n g s Win32 Debug L i b r a r y Output File Name d S t d A f x. c p p S t d A f x. h M F C C + + C + M F C 3) C + + P r o j e c t S e t t i n g s C + + C / C + + C a t e g o r y Precompiled header C + + Not using precompiled headers 2. 1). c. c p p 2) C # include <stdlib.h> 3) Windows API # include <windows.h> _declspec (dllexport) d e c l s p e c ( d l l e x p o r t ) 4) #ifdef WZDDLL_BLD #define DLL declspec(dllexport) #define DLL 5) D L L D L L W Z D D L L _ B L D Developer Studio P r o j e c t / S e t t i n g s Project Settings S e t t i n g s
15 297 All Configurations C / C + + W Z D D L L _ B L D Preprocessor definitions 6) D L L C D L L void DLL WzdMessageBox(LPSTR pszstring); void DLL WzdMessageBox(LPSTR pszstring) : : : 7) D L L C + + D L L class DLL CWzdDllCpp ; 8) C C C C + + C + C C + + C e x t e r n " c " e x t e r n " c " C _ c p l u s p l u s _ c p l u s p l u C + + T R U E C FA L S E C C + + C + + C /* at the start of your C.h file */ extern "C" #endif /* cplusplus */ : : : your C function prototypes : : : /* at the end of your C.h file */ 9) C C + + C C + + 3. Project Settings L i n k. l i b. l i b Object/library modules d l l PAT H D L L D
298 Wi n d o w s D L L D CD Te s t d l l C /* WzdDll.h : NonMFC Dll * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / #if!defined WZDDLL_H #define WZDDLL_H extern "C #endif /* cplusplus */ #ifdef WZDDLL_BLD #define DLL declspec(dllexport) #define DLL void DLL WzdMessageBox(LPSTR pszstring); void DLL DestroyWzdWindow(HWND hwnd); void DLL WzdFunc3(BOOL b); / * * WzdDll.c : NonMFC "C" Dll Using the Win32 API directly * / #include <windows.h> #include <stdlib.h> #include "WzdDll.h"
15 299 BOOL flag=fa L S E ; // must call Win32 API directly void DLL WzdMessageBox(LPSTR pszstring) MessageBox(NULL,pszString,"Wzd DLL",MB_OK); void DLL DestroyWzdWindow(HWND hwnd) D e s t r o y Wi n d o w ( h W n d ); void DLL WzdFunc3(BOOL b) f l a g = b ; C++ // WzdDllCpp.h : C++ NonMFC Dll / / #if!defined WZDDLLCPP_H #define WZDDLLCPP_H #ifdef WZDDLL_BLD #define DLL declspec(dllexport) #define DLL class DLL CWzdDllCpp BOOL m_bflag; p u b l i c : C W z d D l l C p p ( ) ; ~ C W z d D l l C p p ( ) ; void WzdMessageBox(LPSTR pszstring); void DestroyWzdWindow(HWND hwnd); void WzdFunc3(BOOL b); ;
300 // WzdDllCpp.cpp : NonMFC "C++" Dll Using the Win32 API directly / / #include <windows.h> #include <stdlib.h> #include "WzdDllCpp.h" C W z d D l l C p p :: C W z d D l l C p p () m _ b F l a g = FA L S E ; C W z d D l l C p p : : ~ C W z d D l l C p p ( ) // must call the Win32 API directly void CWzdDllCpp::WzdMessageBox(LPSTR pszstring) MessageBox(NULL,pszString,"Wzd DLL Cpp",MB_OK); void CWzdDllCpp::DestroyWzdWindow(HWND hwnd) D e s t r o y Wi n d o w ( h W n d ); void CWzdDllCpp::WzdFunc3(BOOL b) m _ b F l a g = b ; 15.3 84 MFC C + + M F C Developer Studio MFC DLL _declspec (dllexport) 1. M F C 1) N e w Developer Studio N e w P r o j e c t M F C
15 301 A p p Wizard (dll) O K 2) AppWi z a r d D L L Regular DLL M F C MFC Extension DLL M F C M F Regular DLL M F C D L L MFC Extension DLL MFC Extension DLL M F C M F M F C. l i b. d l l. l i b. d l l 3) S t u d i o P r o j e c t / S e t t i n g s P r o j e c t S e t t i n g s S e t t i n g s Win32 Debug L i b r a r y Output Name d 2. M F C 1) A p p Wi z a r d D L L C l a s s Wi z a r d M F C M F _declspec (dllexport) _declspec (dllexport) 2) #ifdef _WINDLL #define DLL declspec(dllexport) #define DLL _ W I N D L L D L L A p p Wi z a r d 3) D L L C + + D L L class DLL CWzdDllCpp ; 3.
302 1) Project Settings L i n k. l i b. l i b Object/library modules 2). d l l PAT H D L L D Shared MFC DLL Regular DLL M F C A F X _ M A N A G E _ S TATE ( ) void CWzdDllMFC::DestroyWzdWindow(HWND hwnd) A F X _ M A N A G E _ S TAT E ( A f x G e t S t a t i c M o d u l e S t a t e ( ) ) ; // rest of function here D CD Te s t d l l // WzdDllMFC.h : MFC Dll / / #if!defined WZDDLLMFC_H #define WZDDLLMFC_H #ifdef _WINDLL #define DLL declspec(dllexport) #define DLL class DLL CWzdDllMFC BOOL m_bflag; p u b l i c : C W z d D l l M F C ( ) ; ~ C W z d D l l M F C ( ) ; void WzdMessageBox(LPSTR pszstring); void DestroyWzdWindow(HWND hwnd); void WzdFunc3(BOOL b);
15 303 ; // WzdDllMFC.cpp : MFC Dll / / #include "stdafx.h" #include "WzdDllMFCx.h" C W z d D l l M F C :: C W z d D l l M F C () m _ b F l a g = FA L S E ; C W z d D l l M F C : : ~ C W z d D l l M F C ( ) // can use MFC classes and static functions void CWzdDllMFC::WzdMessageBox(LPSTR pszstring) A f x M e s s a g e B o x ( p s z S t r i n g ); void CWzdDllMFC::DestroyWzdWindow(HWND hwnd) CWnd wnd; w n d. A t t a c h ( h W n d ); w n d. D e s t r o y Wi n d o w (); void CWzdDllMFC::WzdFunc3(BOOL b) m _ b F l a g = b ; 15.4 85 D L L D L L ( F r e n c h I t a l i a n E s p e r a n t o ) M F C D L L I D
304 M F C D L L I D D L L 1) M F C D L L 2) D L L 3) Developer Studio I D D L L I D I D I I D I D I " M Y D L L _ R E S O U R C E 1 " 4) r e s o u r c e. h I D. h D L L 5) D L L D L CString str; s t r. L o a d S t r i n g ( i d ) ; A f x M e s s a g e B o x ( s t r ) ; CD Te s t d l l